【发布时间】:2014-11-28 13:30:51
【问题描述】:
我已获取 CSIPSIMPLE 代码并重新打包到 com.mycompany.appname
问题是,每当应用程序崩溃时,所有值都会从共享首选项中删除。
为什么?
我的申请是
public class BeemApplication extends Application {
static BeemApplication application = null;
public static SharedPreferences mPref;
public static Editor mEditor;
public BeemApplication() {
}
public static BeemApplication getInstance() {
if(application != null) {
return application;
} else {
return new BeemApplication();
}
}
@Override
public void onCreate() {
super.onCreate();
application = this;
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mEditor = mPref.edit();
}
@Override
public void onTerminate() {
super.onTerminate();
}
}
在活动中我会得到他们喜欢的,
BeemApplication.mEditor.putString(ctx.getString(R.string.pref_online_number), number).commit();
BeemApplication.mPref.getString(ctx.getString(R.string.pref_online_number), number).commit();
【问题讨论】:
-
在
crashes的情况下发布logcat -
“所有值都从共享首选项中删除”——您对此有何证据?
-
确保没有使用 null 键保存您的任何首选项,因为在您的应用尝试加载preferences.xml文件时崩溃后,它可以导致首选项崩溃并且首选项将被重置。
-
记得调用 .commit()
-
@CommonsWare,当我试图获取存储的值时,它会给出默认值