• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Bundling Extras in an Intent Not Working!

Matt M

Lurker
Apr 29, 2010
5
0
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.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones