Multiple Instances of Pending Intent
I created a widget that when clicked activates a PendingIntent. The problem is when I have more than one widget on the screen only the latest one will start the PendingIntent.
I have read some about a unique request code, but not figured this out.
Any ideas how I can have multip开发者_如何学Pythonle widgets and the PendingIntents work for each?
Here is a snippet of my code:
Intent openApp = new Intent(context, RunningTally.class);
openApp.putExtra("widgetId", appWidgetId);
PendingIntent pendingAppIntent =
PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT );
views.setOnClickPendingIntent(R.id.openFull, pendingAppIntent);
So happens that after posting my question, I came up with an answer. I pass in my appWidgetId as the "unique" request code and voila! Here is the snippet now:
Intent openApp = new Intent(context, RunningTally.class);
openApp.putExtra("widgetId", appWidgetId);
PendingIntent pendingAppIntent =
PendingIntent.getActivity(context, appWidgetId, openApp,
PendingIntent.FLAG_CANCEL_CURRENT);
views.setOnClickPendingIntent(R.id.openFull, pendingAppIntent);
精彩评论