[英]Android: SharedPreferences Issue (Multiple SharedPreferences)
[英]Android-Permission Settings and SharedPreferences Issue
我正在开发一个应用程序,并将每个表单数据保存到SharedPreferences。 它工作正常,但是当我销毁我的应用程序时,我回到应用程序的表单数据仍然存在。原因是我的应用程序在运行时需要权限
我试着 :
我尝试了另一种情况,例如销毁应用程序。 打开另一个应用程序,我的表单仍然存在。 只需在设置->应用->权限和禁用权限中 。
Android是否会进行一些检查或进行任何使我的偏好丢失的活动?
我这样创建我的Prefs实用程序:
/**
* 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);
}
}
谢谢
在这里,您可以找到它的工作方式并查看一些示例:
https://developer.android.com/training/basics/data-storage/shared-preferences.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.