0

I have a simple question (hopefully it is simple).

I've tried using adapterviewflipper in widget. I tested this code here.

The code works perfectly fine for me, if there is only one instance of widget in the homescreen. But things get messy when I create another instance of widget. The next button in every widget instance will only affect the last widget created, which is wrong.

Anyone have any idea how to deal with this?

Thanks in advance!

CodingBird
  • 705
  • 2
  • 11
  • 22

2 Answers2

4

The reason is that the PendingIntent you set for each widget instance is seen as identical by the system. You can set different requestCode's for each widget instance. For example, you can define PendingIntent like this:

final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, **appWidgetId**, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Refer to: Multiple Instances Of Widget Only Updating Last widget

Note that in the page above, setData on PendingIntent may not solve the problem. But setting different requestCode always does.

Community
  • 1
  • 1
Yanling
  • 303
  • 2
  • 9
  • THANKS! I've figured it out on my own in the end! :) Though I forgot to write an answer here! Hahaha. But yup what you said its true! :D – CodingBird Oct 18 '13 at 01:50
0

file WidgetProvider.java, onUpdate(), PendingIntent uses request code 0. Replace it with widget id.

final PendingIntent nextPendingIntent = PendingIntent
                .getBroadcast(context, id, nextIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
codeFood
  • 1,241
  • 16
  • 16