Multiple Instances of Pending Intent

AndroidWidget

Android Problem Overview


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 multiple 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);

Android Solutions


Solution 1 - Android

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);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontaralocaView Question on Stackoverflow
Solution 1 - AndroidtaralocaView Answer on Stackoverflow