Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two buttons with PendingIntents - Widget

I'm creating a widget with two buttons. One of them updates the content of the widget and the second one must launch an activity.

I have two PendingIntent for each action, but I can't make them both work. If one works the other one doesn't.

I've revised the code and can't understand what's wrong.

Any help will be very appreciated.

This is the code.

    RemoteViews controls = new RemoteViews(context.getPackageName(), R.layout.miwidget);

    Intent intent = new Intent("actony.com.ACTUALIZAR_WIDGET");
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);


    Intent intentSettings = new Intent();  
    intentSettings.setClass(context,WidgetConfig.class);  


    PendingIntent pendingIntentUpdate = PendingIntent.getBroadcast(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    controls.setOnClickPendingIntent(R.id.BtnActualizar, pendingIntentUpdate);

    PendingIntent pendingIntentSettings =  PendingIntent.getActivity(context, 0, intentSettings, 0);
    controls.setOnClickPendingIntent(R.id.botonSettings, pendingIntentSettings);
like image 966
user986689 Avatar asked Oct 09 '22 15:10

user986689


1 Answers

Try adding the getActivity PendingIntent.FLAG_UPDATE_CURRENT aswell...

 PendingIntent pendingIntentSettings =  
      PendingIntent.getActivity(context, 0, intentSettings, PendingIntent.FLAG_UPDATE_CURRENT);

and if multiple widget's are possible add the widgetId there too.

Make sure both of the activities/broadcasts are listed in the manifest file.

Moreover, try creating the Intent with this constructor:

 Intent intent = new Intent(context,ACTUALIZAR_WIDGET.class);
 Intent intentSettings = new Intent(context,WidgetConfig.class);

add imports if needed.

Hope some of that will make you widget work.

like image 165
GalDude33 Avatar answered Oct 13 '22 11:10

GalDude33