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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With