Reputation: 300
I'm writing an AppWidget where I first have a configure screen where the user makes a selection. Then I want to pass that data on to the actual widget. This must be really simple but I just can't figure out how to do it.
Upvotes: 2
Views: 2574
Reputation: 43412
I just save the data to Preferences. Widget will read these preferences when it's displayed. Anyway you have to use preferences to persist the selected options.
Upvotes: 3
Reputation: 614
Unsure if this is what you're looking for, but to set the RemoteViews from the configure screen, I use the following:
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
// Set RemoteViews
views.setTextViewText(R.id.textview, text);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
// User is finished configuring, effectively closing the configure screen.
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
More information here: http://developer.android.com/guide/topics/appwidgets/index.html#Configuring
Upvotes: 2