Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Instances of Pending Intent

Tags:

android

widget

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); 
like image 826
taraloca Avatar asked Sep 16 '10 19:09

taraloca


People also ask

What is a pending intent give example?

A PendingIntent is a token that you give to a foreign application (e.g. NotificationManager, AlarmManager, Home Screen AppWidgetManager, or other 3rd party applications), which allows the foreign application to use your application's permissions to execute a predefined piece of code.

What is the significance of the pending intent?

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it.

What is intent and pending intent?

PendingIntent is a wrapper of Intent . The foreign app that receives the PendingIntent , doesn't know the content of Intent which is wrapped by PendingIntent . The mission of foreign app is to send back the intent to owner when some conditions are met (For example: alarm with schedule, or notification with click...).


1 Answers

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); 
like image 73
taraloca Avatar answered Sep 23 '22 12:09

taraloca