Replying to my own post for future reference.

This is due to the way PendingIntents work and are automatically
reused.
Quoting the PendingIntent Javadoc:
"If the creating application later re-retrieves the same kind of
PendingIntent (same operation, same Intent action, data, categories,
and components, and same flags), it will receive a PendingIntent
representing the same token if that is still valid, and can thus call
cancel() to remove it."

BoD



On Jun 14, 9:19 pm, BoD <[email protected]> wrote:
> Hi!
>
> I'm making a little AppWidget that should be configured when you first
> add it and also when you click on it.
>
> I figured, since clicking on it should do the same as the "creation"
> event, why not try to use the same code?
>
> My configuration Activity should not know or care, whether it was
> called for a creation event or an "already exists, wants to be
> configured" event.
>
> So I extend AppWidgetProvider, create a RemoteViews for my AppWidget
> and do this in onUpdate():
>
>             Intent intent = new Intent(context,
> ConfigureActivity.class);
>             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
>             intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
> appWidgetId);
>
>             PendingIntent pendingIntent = PendingIntent.getActivity
> (context, 0, intent, 0);
>
>             views.setOnClickPendingIntent(R.id.buttonImage,
> pendingIntent);
>
> For some reason it's not working as I'd like:
> in my ConfigureActivity when I look at getIntent().getExtras
> ().extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID), it returns
> always the same id: the first one that was configured.
>
> Now the strange part:
> if in the code above I add this line:
>
>             intent.setData(ContentUris.withAppendedId(Uri.EMPTY,
> appWidgetId));
>
> then it works correctly and in my ConfigureActivity getIntent
> ().getExtras().extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID)
> returns the correct id, the id of the widget I clicked on.
>
> Surely there is an explanation but I don't see it.
> Please help! :)
>
> Thanks a lot!
>
> BoD
--~--~---------~--~----~------------~-------~--~----~
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