I am developing a simple widget which has a couple of buttons in its
layout.

Before the widget gets added, the configuration activity is displayed,
where the user can choose if the widget makes any sounds when the
buttons get pressed or not.

Thus, a user can put two instances of the widget, one where he chose
sound to be activated and another where he chose the opposite.
However, I can not seem to be able to reproduce the expected behavior
(that one reproduces sound and the other doesn't).

The buttons' behavior varies according to the flags specified to the
PendingIntent:

- FLAG_UPDATE_CURRENT seems to override the previous intent/setting
- no flags (0x00) seems to ignore any intent/setting after the first
instance of the widget is put.

What I want to do: I want to be able to configure different instances
of the same widget to behave in a different way, according to what the
user specified in the configuration activity. I am attempting to do
this with the help of the appWidgetId of each instance:

I have tried the following when assigning an action to the click of
the button:

                        int mAppWidgetId=appWidgetIds[i];
                        Intent intent1=new Intent();
                        intent1.setAction("com.spartancoders.intenttest.TEST");
                        Log.d("TEST ONUPDATE",""+mAppWidgetId);
                        intent1.putExtra("id", mAppWidgetId);
                        PendingIntent pi1 = PendingIntent.getBroadcast(context,
0,intent1,PendingIntent.FLAG_UPDATE_CURRENT);

And in the onReceive() method:

                Bundle extras = arg1.getExtras();
                if (arg1!=null){
                        Log.d("TEST ONRECEIVE",""+extras.getInt("id"));
                }

This results in the first widget acting properly (The IDs printed in
logcat are as expected)
When adding a second widget, however, the first widget starts
reporting the second widget's appWidgetId in its onReceive(), when it
previously did no such thing.
(because of the FLAG_UPDATE_CURRENT, I guess)

How can one make different instances behave in a different way?
Is there a way to do this with the help of the appWidgetId?

I have elaborated a widget application for the purpose of debugging
this problem which tries to be minimal, while reproducing the (un)
desired behavior:

http://www.2shared.com/file/8243059/b6519584/IntentTesttar.html

Any help is appreciated, thanks!
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to