Search code examples
androidandroid-widgetappwidgetprovider

Getting settings from configure activity


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


Solution

  • 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.