【发布时间】:2015-07-21 16:05:26
【问题描述】:
我正在我的 MainActivity 中创建一个共享首选项,然后我想在我的 IntentService 的共享首选项中保存一个值;然而;我不断得到默认值,而不是我保存的值。
这是我在 MainActivity 中创建 SharedPreference 的代码:
SharedPreferences prefs = this.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putString("inter", inter).apply();
在我的 IntentService 类中:
protected void onHandleIntent(Intent intent) {
SharedPreferences preferences = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
final String inter = preferences.getString("inter", "default_no");
}
【问题讨论】: