Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 重新启动后丢失SharedReferences数据_Android_Variables_Sharedpreferences - Fatal编程技术网

Android 重新启动后丢失SharedReferences数据

Android 重新启动后丢失SharedReferences数据,android,variables,sharedpreferences,Android,Variables,Sharedpreferences,当我按下按钮并在onCreate()方法上还原它时,我使用SharedReferences保存了两个变量,当关闭并重新打开应用程序时,一切正常,但重新启动后,所有值都设置为默认值。为什么呢?我是否必须以其他方式保存它以防止重新启动后丢失值 您是否在SharedReferences.Editor上调用.apply()/.commit()?当然可以。我刚才说一切正常,但只有在重新启动后我才能得到默认值。你能发布一些代码吗?对不起,我太傻了,没有看到我的愚蠢错误。在还原变量之前,我会检查一些警报是否开

当我按下按钮并在
onCreate()
方法上还原它时,我使用SharedReferences保存了两个变量,当关闭并重新打开应用程序时,一切正常,但重新启动后,所有值都设置为默认值。为什么呢?我是否必须以其他方式保存它以防止重新启动后丢失值

您是否在SharedReferences.Editor上调用.apply()/.commit()?当然可以。我刚才说一切正常,但只有在重新启动后我才能得到默认值。你能发布一些代码吗?对不起,我太傻了,没有看到我的愚蠢错误。在还原变量之前,我会检查一些警报是否开启,但在重新启动后警报会关闭,因此变量不会被还原。再次为垃圾邮件道歉