1. Check out our companion app, Forums for Android! Download from Google Play

Bundling Extras in an Intent Not Working!

Discussion in 'Application Development' started by Matt M, Apr 29, 2010.

  1. Matt M

    Matt M Member
    Thread Starter
    5

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

    Sep 2, 2010
    1
    0
    5
    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...