The code appears fine (if you don't count the made-up "abcd://" scheme...
and you don't need a URI since you're using a unique requestCode)...
and should produce distinct pending intents for distinct app widget IDs.
You may want to log the pending intent objects (using String.valueOf), it
should look like this:
PendingIntent{416c5d38: android.os.BinderProxy@41709960}
The number after BinderProxy should be unique for each unique app widget id
if things are working as expected.
Oh, if you've been making changes incrementally, try rebooting the device
or adding PendingIntent.FLAG_UPDATE_CURRENT rather than 0 for the last
parameter to getBroacast.
-- K
2012/5/16 Skip Morrow <[email protected]>
> Kostya (sorry, I spelled your name wrong last time),
> Thanks again for writing!
>
> I must be close, but dang if I don't see the problem. Here's my code
> where I create the PendingIntent. Do you see anything that I am doing wrong?
>
> Intent intent = new Intent(ctx, PhcaAppWidgetProvider.class);
> intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> intent.setAction(ACTION_CLICK);
> intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
> Uri data = Uri.withAppendedPath(
> Uri.parse("ABCD" + "://widget/id/")
> ,String.valueOf(appWidgetId));
> intent.setData(data);
> Log.d(MY_DEBUG, "Provider.Added intent extra \"" +
> AppWidgetManager.EXTRA_APPWIDGET_ID + "\" = " + appWidgetId);
>
> PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx,
> appWidgetId, intent , 0);
> views.setOnClickPendingIntent(R.id.phca_appwidget_layout,
> pendingIntent);
>
>
>
> On Wednesday, May 16, 2012 12:30:05 PM UTC-4, Kostya Vasilyev wrote:
>>
>> 2012/5/16 Skip Morrow <[email protected]>
>>
>>> Koysta, thanks for replying!
>>>
>>> Are you saying that it isn't possible?
>>>
>>
>> No, I'm not saying that.
>>
>>
>>> Because I have app widgets on my desktop right now that I have multiple
>>> instances of, and they all do something different when clicked.
>>>
>>
>> Right.
>>
>>
>>>
>>> I've been trying to figure this one thing out for three days and for the
>>> life of me I can't crack the code.... *sigh*
>>>
>>
>> The heart of the issue is creating distinct PendingIntent objects for
>> associating with distinct widgets.
>>
>> There is a number of ways to do it:
>>
>> 1) By using a unique requestCode in PendingIntent.getBroadcast or
>> getActivity. The app widget id would do nicely.
>>
>> 2) By specifying a unique data URI in the Intents used to create your
>> PendingIntent objects
>>
>> 3) As a variation of 2, you can "serialize" the extras into this URI,
>> like this:
>>
>> Intent intent = new Intent(context, StackWidgetService.class);
>> intent.putExtra(AppWidgetManag**er.EXTRA_APPWIDGET_ID,
>> appWidgetIds[i]);
>>
>> *intent**.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)))*
>>
>> ( taken from the app widget docs at https://developer.android.**
>> com/guide/topics/appwidgets/**index.html#implementing_**collections<https://developer.android.com/guide/topics/appwidgets/index.html#implementing_collections>
>> )
>>
>> In this case, the intent would need to be "unserialized" on the receiving
>> side by using Intent.parse(String uri, int flags).
>>
>> -- K
>>
>>
>>>
>>> On Wednesday, May 16, 2012 12:13:53 PM UTC-4, Kostya Vasilyev wrote:
>>>
>>>> http://developer.android.com/**r**eference/android/app/**PendingIn**
>>>> tent.html<http://developer.android.com/reference/android/app/PendingIntent.html>
>>>>
>>>> >>>
>>>> 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
>>>> <<<
>>>>
>>>> Note that the list of things making an intent unique does not mention
>>>> extras.
>>>>
>>>> -- K
>>>>
>>>> 2012/5/16 Skip Morrow
>>>>
>>>>> I am trying to create an AppWidget that allows for independently
>>>>> configured multiple instances. I can create the AppWidgets just fine, but
>>>>> when I click on them, they always want to do the same thing. So I have
>>>>> searched high and low, and everyone talks about putting the appWidgetId in
>>>>> an extra in the intent. I have tried that, but even the extras come in all
>>>>> the same. They always hold the appWidgetId for the lat-added widget. Here
>>>>> is a post where someone supposed ly it this way:
>>>>> http://stackoverflow.com/****questions/4225197/android-**mult**
>>>>> iple-appwidgets-playing-**difere**nt-sounds<http://stackoverflow.com/questions/4225197/android-multiple-appwidgets-playing-diferent-sounds>.
>>>>> I have posted on StackOverflow, trying to get some help, but no one has
>>>>> responded ( http://stackoverflow.com/**quest**ions/10607518/android-**
>>>>> appwidge**t-multiple-instances<http://stackoverflow.com/questions/10607518/android-appwidget-multiple-instances>).
>>>>> I was hoping that someone here could point me to some actual complete
>>>>> working code that I can look at and see where I am missing something.
>>>>> Please? :)
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to android-developers@**googlegroup*
>>>>> *s.com <[email protected]>
>>>>> To unsubscribe from this group, send email to
>>>>> android-developers+**unsubscribe**@googlegroups.com<android-developers%[email protected]>
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/**group**/android-developers?hl=en<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 android-developers@**
>>> googlegroups.com <[email protected]>
>>> To unsubscribe from this group, send email to
>>> android-developers+**[email protected]<android-developers%[email protected]>
>>> For more options, visit this group at
>>> http://groups.google.com/**group/android-developers?hl=en<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
>
--
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