How do I reopen the configuration activity for a widget after it has been added to the homescreen?
The following code from a Google search does not work because the widget id in the extra does not carry through to the activity:
String ACTION_WIDGET_CONFIGURE = "ConfigureWidget";
Intent configIntent = new Intent(context, Configuration.class);
configIntent.setAction(ACTION_WIDGET_CONFIGURE);
configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
views.setOnClickPendingIntent(R.id.editButton, configPendingIntent);
OK, I'm a year too late, but I was just looking for the same answer as you and noticed a missing flag in your code, which was the answer to a different problem I had a couple of days ago concerning pending intents, extras and widgets. Try changing this line of your code:
PendingIntent configPendingIntent
= PendingIntent.getActivity(context, 0, configIntent, 0);
to this:
PendingIntent configPendingIntent
= PendingIntent.getActivity(context, 0, configIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent
will reuse existing cached intents that match new ones and the "match" does not consider extras, so new extras can be ignored. Adding FLAG_UPDATE_CURRENT
makes PendingIntent
write the extras into the cached intent (or something like that).
Anyway, the above worked for me just now (though I also used AppWidgetManager.ACTION_APPWIDGET_CONFIGURE
as the action name, if that makes any difference).
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