Johan B
Johan B

Reputation: 300

Widget: Get data from configure Activity to AppWidgetProvider

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

Answers (2)

Fedor
Fedor

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

jeffh
jeffh

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

Related Questions