[英]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.