簡體   English   中英

Android權限設置和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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM