Move the call to appWidgetManager.updateAppWidget inside the loop.

-- K

2012/8/6 f.Audire <[email protected]>

> Hi, I dont understand why my PendingIntents arent unique. The toast in
> OnReceive always shows the Id of the last created Widget .
>
> @Override
>     public void onUpdate(Context context, AppWidgetManager
> appWidgetManager,
>             int[] appWidgetIds){
>    super.onUpdate(context, appWidgetManager, appWidgetIds);
>
>    RemoteViews views = new RemoteViews(context.getPackageName(),
> R.layout.widget_layoutmain);
>    for(int j = 0;j < appWidgetIds.length;j++){
>             Intent i = new Intent(context.getApplicationContext(),
> BatteryProvider.class);
>             i.setAction("MyCode");
>             i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
> appWidgetIds[j]);
>             i.setData(Uri.parse(i.toUri(Intent.URI_INTENT_SCHEME)));
>             PendingIntent pi = PendingIntent.getBroadcast(context,j, i,0);
>             views.setOnClickPendingIntent(R.id.imageViewLayer,pi);
>    }
>    appWidgetManager.updateAppWidget(appWidgetIds, views);
> }
>
> @Override
>     public void onReceive(Context context, Intent intent) {
>
>    super.onReceive(context, intent);
>    Bundle extras = intent.getExtras();
>    Toast.makeText(context,
> String.valueOf(extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID)),
> Toast.LENGTH_SHORT).show();
> }
>
> I have have no Idea why this doesnt work. I've seen so many examples that
> do almost exactly the same. I have tried different flags, different data,
> different actions and different requestCodes but still I seem to have only
> one PendingIntent.
>
> What am I doing wrong?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to