在三星 S7 牛轧糖中的某个时间后,共享首选项变为零

Shared Preferences get nil after sometime in Samsung S7 Nougat

我正在 SharedPreferences 中保存一个密钥。当试图立即检索它时,它 returns 我的价值。但是一段时间后它 returns a nil value。这种情况尤其发生在三星 S7 牛轧糖上,并且几乎适用于所有其他设备,例如 Nexus、Mi、Oppo 等。我交叉检查了几次,但我 没有改变密钥之间的值 保存和检索。

我注意到 Samsung 在卸载应用程序后没有清除首选项(我在 Samsung S6 中检查过)。那么三星设备是否有任何问题或是否存在任何漏洞我不考虑。 请帮忙!

<application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="false"
        android:hardwareAccelerated="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:launchMode="singleTask"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".activities.SplashActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <data
                    android:host=“xx.com"
                    android:scheme=“xx”
                    android:pathPrefix="/"/>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.MainActivity"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.AutomatedTestActivity"
            android:screenOrientation="portrait" />
        <activity android:name=".activities.PasswordCancelActivity"></activity>
    </application>

I have noticed that Samsung doesnt clear Preferences after uninstalling the app (I checked in Samsung S6).So is there any problem with the Samsung devices or is there any loop hole im not considering. Please help!

在 android 清单应用程序标记中更改 android:allowBackup:false。 即使应用程序被卸载,它的真实备份也会被存储。

来自 android 开发者文档

android:allowBackup Whether to allow the application to participate in the backup and restore infrastructure. If this attribute is set to false, no backup or restore of the application will ever be performed, even by a full-system backup that would otherwise cause all application data to be saved via adb. The default value of this attribute is true.