Bundling Extras in an Intent Not Working!

Put your problem here if it does not fit any of the other categories.

Bundling Extras in an Intent Not Working!

Postby Matt M » Fri Apr 30, 2010 2:37 am

Hello,

In my AppWidgetProvider class, in the onUpdate(...) method, I sort through the array of id's and inside the loop create an intent to launch the activity with information specific to the widget that is being clicked, the intent looks like this:

Intent intent = new Intent(context, MyActivity.class);
intent.putExtra("WIDGET ID", appWidgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);

Then, in the activity I collect the extras:

Intent intent = getIntent();
Bundle extras = intent.getExtras();
int id = extras.getInt("WIDGET ID", AppWidgetManager.INVALID_APPWIDGET_ID);

For testing purposes when the activity is launched by clicking on a widget I display the int id from above, but no matter how many widgets I add or which one I click on it always displays the same constant value!

Any ideas??

Thank you!

Matt.
User avatar
Matt M
Developer
Developer
 
Posts: 30
Joined: Tue Apr 27, 2010 7:35 pm

Top

Re: Bundling Extras in an Intent Not Working!

Postby pskink » Fri Apr 30, 2010 7:24 am

Matt M wrote:Hello,

In my AppWidgetProvider class, in the onUpdate(...) method, I sort through the array of id's and inside the loop create an intent to launch the activity with information specific to the widget that is being clicked, the intent looks like this:

Intent intent = new Intent(context, MyActivity.class);
intent.putExtra("WIDGET ID", appWidgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

For testing purposes when the activity is launched by clicking on a widget I display the int id from above, but no matter how many widgets I add or which one I click on it always displays the same constant value!

Any ideas??

Thank you!

Matt.


try adding different "requestCode", e.g.:
PendingIntent.getActivity(context, appWidgetId, intent, 0);
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby Matt M » Fri Apr 30, 2010 6:14 pm

THAT WORKED THANK YOU!!
User avatar
Matt M
Developer
Developer
 
Posts: 30
Joined: Tue Apr 27, 2010 7:35 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 15 guests