I created a simple appwidget which shows digital clock, and I set a PendingIntent for that clock.(i.e) when the user tap on the textview a dialpad is opened. It works perfectly. But when i opens some application like Car Home and then exit from the Car Home will makes just a flash my Homescreen. And my widget is now gone to not responding state. I don’t know i m going wrong. Past 2 days i m googling for this. Anyone please help.
java code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
context.startService(new Intent(UpdateService.ACTION_UPDATE));
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, dial, 0);
remoteViews.setOnClickPendingIntent(R.id.Time, pendingIntent);
for (int i = 0; i < appWidgetIds.length; i++) {
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
}
}
AppwidgetProvider:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="150dip"
android:minHeight="72dip"
android:initialLayout="@layout/main" />
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#00000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" >
<TextView
android:id="@+id/Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="none"
android:textSize="56sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:shadowColor="#C0000000"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="3.0" />
</RelativeLayout>
</FrameLayout>
Please try
AppwidgetManager.updatewidget()inonupdateof yourAppWidgetManagermethod.