I have a service the controls a mediaplayer and updates a widget. I
added 3 ImageViews to change song (Prev and Next) and to Play/Pause. I
added custom BroadcastReceivers, one for each ImageView. But some some
reason, i receive broadcast randomly. Sometime i get 3 broadcast,
sometimes i get 8. And they are broadcast the should only appear when
i tap on one of the 3 ImageViews.

Here is the code for my widget:
public class GMWidget extends AppWidgetProvider {
    private String TAG = "GMWidget";


    @Override
    public void onEnabled(Context context) {
    }

    String LOG = "GMWidget";
    @Override
      public void onUpdate(Context context, AppWidgetManager
appWidgetManager,
          int[] appWidgetIds) {
        Log.w(LOG, "onUpdate method called");



    }

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        String action = intent.getAction();
        //Log.d(TAG,"CLICKK: " + action);
        Intent i = new Intent();
        i.setAction(action);
        context.sendBroadcast(i);

    }


}


And here is where i set the "listeners"

public void SetWidgetListener() {
                Log.d(TAG, "SetListener called");
                 RemoteViews updateViews = null;
                    updateViews = new RemoteViews(this.getPackageName(),
R.layout.widget);
                    Intent intent = new Intent(this, GMWidget.class);
                    intent.setAction(WIDGET_PAUSE_PLAY);
                    PendingIntent WidgetPausePlay = 
PendingIntent.getBroadcast(this,
0, intent, 0);
                    updateViews.setOnClickPendingIntent(R.id.pbWidMediaPlay,
WidgetPausePlay);

                    Intent Widget_Next_intent = new Intent(this, 
GMWidget.class);
                    Widget_Next_intent.setAction(WIDGET_NEXT);
                    PendingIntent WidgetNext = PendingIntent.getBroadcast(this, 
0,
Widget_Next_intent, 0);
                    updateViews.setOnClickPendingIntent(R.id.pbWidMediaNext,
WidgetNext);

                    Intent Widget_Prev_intent = new Intent(this, 
GMWidget.class);
                    Widget_Prev_intent.setAction(WIDGET_PREV);
                    PendingIntent WidgetPrev = PendingIntent.getBroadcast(this, 
0,
Widget_Prev_intent, 0);
                        updateViews.setOnClickPendingIntent(R.id.pbWidMediaPrev,
WidgetPrev);

            ComponentName thisWidget = new ComponentName(this,
GMWidget.class);
            AppWidgetManager manager =
AppWidgetManager.getInstance(this);
            manager.updateAppWidget(thisWidget, updateViews);
        }

But i only set the listeners when i receive "APPWIDGET_ENABLED"

Hope someone can help me.
Thanks in advance!

-- 
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