1

I have a widget that sets up a number of pendingIntents. All is working just fine on the widget as long as I only have a single widget on the home screen.

For the time being I decided that I was going to limit the user to only one of my home screen widgets. If one is already in use the ConfigureActivity gives the user an alertDialog box telling them they can't add a second one and then sets setResult(RESULT_CANCELED, null) and then finish().

This works just fine and keeps the user from being able to setup any further home screen widgets but for the one that is already in place most of my pendingIntents won't fire. Logcat tells me "Cannot send pending intent:"

Each of the pendingIntents is set to start up a service that is used to update the widget. If I remove the widget and reset it up it works just fine again, until I try to add a second widget. It is a bit baffling to me at this point. Anyone have any ideas as to why starting to add the 2nd widget but not completing it would cancel out my previous pendingIntents?

Incase it matters, the pendingIntents where setup with FLAG_CANCEL_CURRENT.

Here is the code used to set my intent and pendingIntents.

Intent intentDialog = new Intent(getBaseContext(), ScheduleActionsActivity.class);
intentDialog.putExtra("Action", ACTION_ENTER_SCHEDULE);  
intentDialog.setAction("abc.hwRowOne");  
intentDialog.putExtra("scheduleId", sch.getId());  
intentDialog.putExtra("scheduleDescription", sch.getDescription());  
PendingIntent pendingIntentDialog1 = PendingIntent.getActivity(getBaseContext(), 0, intentDialog, PendingIntent.FLAG_CANCEL_CURRENT);  
views.setOnClickPendingIntent(R.id.hwRowOne, pendingIntentDialog1);  

The line where intentDialog.setAction() changes to be unique for each row of the widget, so I thought that was making my pendingIntent unique as well.

I saw this answer last night after posting my question but I am not sure why/how it works and I am unsure where to put it in my area. It appears to set a unique data for each intent, but that is what I thought my .setAction() was doing. Multiple Instances Of Widget Only Updating Last widget

So to answer your question, no I am not using the appWidgetId at all in my intents, do I just need to pass it along as a putExtra() then on the intentDialog?

Community
  • 1
  • 1
Eric
  • 83
  • 8
  • Have you properly used WidgetID to indicate the PendingIntent that which widget need to be updated? Whenever you have more than one widget to update it from service you need to pass the correct widget id to it. – MKJParekh Jul 12 '12 at 05:50

1 Answers1

0

The answer to this question solved my issues: Multiple Instances Of Widget Only Updating Last widget

I have no idea why adding the setData(uri) works but it did allow me to have more than one widget on the home screen now and the pendingIntents are unique and firing as I would expect them.

On the safe side I am also adding the appWidgetId to the intent and might need it later if I decide to allow more than one widget per device.

Community
  • 1
  • 1
Eric
  • 83
  • 8