problems with getting value from SharedPreferences
i have this code i call from a service.
prefs = getSharedPreferences(homeConfigure.APP_PREF_NAME, Context.MODE_PRIVATE);
city = prefs.getString(CITY + appWidgetId,"nothing");
it returns the correct value stored. but subsequent calls to the service through an AlarmManager in the service class returns the value "nothing".
what could be wrong?
i save them in the homeConfigure activity like this:
city = cityText.getText().toString();
Editor editor = prefs.edit();
editor.p开发者_开发百科utString(CITY + appWidgetId,city);
editor.commit();
and the appwidget is obtained from an intent in the onCreate() of the configuration class when the widget is first added:
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
Try using getDefaultPreferences(context) instead.
精彩评论