I have multiple instances of a widget.
When I click on a widget the configuration activity is started as expected, the activity retrieves the corresponding widget id (I followed this post explaining how to differentiate intents):
Intent configIntent = new Intent(context, WidgetConfigureDisplayActivity.class);
configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, configIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.mood_main_layout, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
So everything works fine except when I use the home button (and not the back one) on the configuration activity.
On home screen, if I click on another widget instance, the configuration activity is displayed but it is not updated with the new widget instance configuration (widget id in the extra is unchanged).
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
I believed the purpose of the FLAG_UPDATE_CURRENT flag was to update the widget id in the activity but it doesn't seem to work (I tried to override onNewIntent, onResume methods with no luck). Playing with launchMode & other flags doesn't help either.