我正在开发一个应用程序,我将每个表单数据保存到SharedPreferences。它工作正常,但是当我毁了我的程序,我回应用程序中的表单数据仍然exists.Cause我的应用程序需要在运行Android权限设置和SharedPreferences问题
允许我尝试:
- 填写我的第一形式
- 转到我的第二个表格并填写
- 回到第一形式(因运行时允许存在于这里,当一个按钮点击)
- 打开设置
- 禁用Pe的rmission
- 打开我的应用程序
- 我的第二个表格的数据丢失
我尝试另一种情况下,像摧毁应用程序。打开另一个应用,我的表单仍然存在。只需在设置 - >应用程序 - >权限和禁用权限。
是Android做一些检查或任何活动,使我的 偏好损失?
我创造我的首选项UTIL这样的:
/**
* Initialize the Prefs helper class to keep a reference to the SharedPreference for this
* application the SharedPreference will use the package provinceName of the application as the Key.
*
* @param context the Application context.
*/
public static void initPrefs(Context context) {
if (mPrefs == null) {
String key = context.getPackageName();
if (key == null) {
throw new NullPointerException("Prefs key may not be null");
}
mPrefs = context.getSharedPreferences(key, Context.MODE_PRIVATE);
}
}
谢谢
请提供一些码。你在哪里存储和加载值的形式(S)? – deHaar