I have created an app widget using collection for my app, The widget shows date and list of items on that particular date. Everything works fine and the widget is updating as re
When you create the PendingIntents
in updateAppWidget
, for each widget, you create these two:
PendingIntent nextButtonPendingIntent = PendingIntent.getBroadcast(context, widgetId, nextButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent prevButtonPendingIntent = PendingIntent.getBroadcast(context, widgetId, prevButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
For both, you set the second argument to widgetId
. The PendingIntent system doesn't look to see if the Intent
argument is different. (In fact, it definititely shouldn't do this - otherwise you couldn't update an existing PendingIntent to a new Intent.) This means that nextButtonPendingIntent
and prevButtonPendingIntent
end up the same.
The solution is to put known, distinct, numbers in that argument and to put other useful information (like the widget Id) inside the intent:
nextButtonIntent.putExtra("widget_id", widgetId);
And to retrieve it in the onReceive():
int widgetId = intent.getIntExtra("widget_id");