Question

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

Was it helpful?

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.

OTHER TIPS

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); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top