Bundling Extras in an Intent Not Working!


Last Updated:

  1. Matt M

    Matt M Member This Topic's Starter

    Joined:
    Apr 29, 2010
    Messages:
    5
    Likes Received:
    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.
     

    Advertisement
  2. dickydoouk

    dickydoouk New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    I had a similar problem you need to insure that each time you create an intent you use a unique request code i.e.

    PendingIntent.getBroadcast(context, requestCode++, intent, 0);

    Where requestCode is an integer field in your activity.

    Hope that helps.
     

Share This Page

Loading...