When I'm adding single widget I can configure it properly and it's updated as supposed to after initial configuration. But when I add second and next instances of widget with the same or different configuration onUpdate is not triggered. Well, to be specific onUpdate is executed just before Configuration is set, when Configuration Activity is on top, so it works like:
1 widget - OK
2 widgets - First OK, Second not updated
3 widgets - First OK, Second OK, Third not updated
and so on.
Behavior tested on Android 4.3. I've no idea why update is not working as supposed to.
"OK" Button in Configuration Activity (straight from: http://developer.android.com/guide/topics/appwidgets/index.html#Configuring):
public void ok(View v){
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget_lay);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Log.e("mAppWidgetId", "id: "+mAppWidgetId);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
saveSettings();
finish();
}
OnUpdate part in Widget Provider:
ComponentName thisWidget = new ComponentName(context, MyWidget.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
for (int widgetId : allWidgetIds) {
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
int myConfig = settings.getInt("myConfig"+widgetId, -1);
if(myConfig != -1){
Log.d("widget id", widgetId+" ");
updateWidget(db, widgetId, myConfig);
}