0

I need help with following situation. I have widget with configure activity. In the activity is spinner with some values, which should affect widget look (only text in one TextView). At this time, I set AlarmManager to widget update (service) and modify TextView in Configure activity. This works fine, but when I restart phone, alarm isn't set anymore and I should set It again. I can't do it, because settings from Configure activity is lost.

There is solution - save AppWidgetID with widget settings to database, but I think, it's not the best solution. A problem is, that onUpdate method of AppWidgetProvider is called before onCreate method of ConfigureActivity.

In brief, I need get some settings from Configure Activity, pass it to AppWidgetProvider and update widget.

Thanks in advance

skywall
  • 3,956
  • 1
  • 34
  • 52

2 Answers2

0

Sounds like a job for SharedPreferences. Use your configure activity to set preference values and read them from your widget. Use PreferenceManager.getDefaultSharedPreferences(Context) to access the shared preferences.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • SharedPreferences was my first idea how to resolve it. Saving is ok, but how can I say AppWidgetProvider that widget with specific AppWidgetId has to be updated? – skywall Jul 31 '12 at 15:41
  • @skywall - The mechanism for updating the widget from the configuration activity is described [here](http://developer.android.com/guide/topics/appwidgets/index.html#UpdatingFromTheConfiguration). You retrieve the widget ID from the intent that launches the configuration activity. – Ted Hopp Jul 31 '12 at 21:19
  • Thanks, finally I've used SharedPreferences and onReceive method of AppWidgetProvider. – skywall Aug 02 '12 at 11:14
0

What about a using shared preferences? If you need to save some preference settings related to your application, you could use this solution.

Something like this:

SharedPreferences sharedPreference = getSharedPreferences(PREFS_NAME, 0);
String prefName = sharedPreference.getString(YOUR_PREF_NAME, DEFAULT_VALUE); 
sataniccrow
  • 372
  • 2
  • 7