In my widget provider, I have the following code:
for (int widget_id : appWidgetIds) {
Log.d(TAG, "Widget Id: " + widget_id);
RemoteViews remoteViews;
Widget widget;
while (true) {
try {
widget = Widget.load(context, Widget.class, widget_id);
break;
}
catch (Exception ex) {
Log.e(TAG, "Exception!", ex);
}
}
// Widget is assigned to user
if (widget != null) {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_with_user);
remoteViews.setCharSequence(R.id.user_text, "setText", widget.user.name);
remoteViews.setUri(R.id.avatar, "setImageURI", Uri.parse(widget.user.avatar));
}
else {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent configIntent = new Intent(context, ConfigureWidget.class);
configIntent.setAction(ACTION_WIDGET_CONFIGURE);
configIntent.putExtra("widget_id", widget_id);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_ONE, configIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.configure_text, configPendingIntent);
}
appWidgetManager.updateAppWidget(widget_id, remoteViews);
}
In the else section, I'm launching a configuration activity and trying to pass the widget id to it. However, the bundle is always null:
Bundle extras = getIntent().getExtras();
if (extras != null) {
int widget_id = extras.getInt("widget_id");
}
How can I get the widget id to the launched activity?