Reconfigure Widget After It Has Been Added
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(AppW开发者_JAVA技巧idgetManager.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).
Unfortunately you don't: the widget spec as it currently exists does not support reconfiguration of widgets through the widget configuration activity.
What you can do is launch your widget configuration activity and track the specific widget ID manually: once the new settings are in place you can then update the widget manually using the appropiate manager method. You won't be able to use the same code path as a new widget does, however.
精彩评论