My Android app Transdroid offers several home screen widgets. Every AppWidget has 2 'buttons' (ImageButton), one starts the app and one starts some activity that refreshes the AppWidget content. Pretty simple. Here is a screenshot. The widget code is at my Google Code website, but most importantly:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_15);
views.setOnClickPendingIntent(R.id.widget_action, PendingIntent.getActivity(context, 0, new Intent(context, Transdroid.class), 0));
appWidgetManager.updateAppWidget(id, views);
The problem is: the widget's onUpdate is not called after the Home process is restarted, and hence the PendingIntents used to attach functionality to the buttons is lost.
It's fairly easy to reproduce.
- Start an emulator
- Add a widget (that uses a PendingIntent to, say, start an activity)
- Click the button to see it actually works
- Force kill the home proces ('adb -e shell kill 96' where 96 is the PID of android.process.acore)
- The widget's button doesn't work any more.
More precise: no onReceive and thus no onUpdate is called when the android.process.acore Home process is restarted. In turn, no Intent is attached.
Anyone experienced the same problem and knows how to circumvent this problem?