简体   繁体   English

清除数据后从共享的偏好中获取价值

[英]Getting value from shared preference after clear data

I am setting some value in shared preference at the time when my app is getting installed. 安装我的应用程序时,我在共享首选项中设置了一些值。

Now if the user has done clear data then that will be gone and the user has not installed the app again which means that value won't be set again. 现在,如果用户已完成清除数据,则该数据将消失,并且用户将不会再次安装该应用程序,这意味着不会再次设置该值。

So is there any way I can get that value which I have stored in preference at the time of installation of an app after the user has cleared the data? 那么,在用户清除数据后,有什么方法可以获取我在应用安装时优先存储的值?

You can`t restore data without saving all your data into the server after onPause, but you can use sync account adapter Sync adapter or Firebase for storing this data and restore it after application reinstall. 在onPause之后,您必须将所有数据保存到服务器中才能还原数据,但是可以使用同步帐户适配器Sync适配器或Firebase来存储此数据,并在重新安装应用程序后将其还原。 Remember that sync is asynchronously and some data may be lost. 请记住,同步是异步的,某些数据可能会丢失。 In other cases if you have WRITE_INTERNAL_STORAGE permission you can save data on SD card, but not in the app folder. 在其他情况下,如果您具有WRITE_INTERNAL_STORAGE权限,则可以将数据保存在SD卡上,但不能保存在app文件夹中。

You can not able to retrieve the saved data after user clicks on clear data and clear cache button. 用户单击清除数据和清除缓存按钮后,您将无法检索已保存的数据。 Because all the data stored using Shared Preferences are store in the local only we are not using any server. 因为使用“共享首选项”存储的所有数据仅存储在本地,所以我们不使用任何服务器。 The best example is when you already logged into Facebook and you are doing the same(Clear data and cache) for Facebook app, then again when you will open Facebook, it will ask you to login again because your all credentials are stored in local that is it may be using Shared Preference or SQLite. 最好的例子是,当您已经登录Facebook并且对Facebook应用执行相同的操作(清除数据和缓存)时,然后再次打开Facebook时,它将要求您再次登录,因为您的所有凭据都存储在本地是否可能使用共享首选项或SQLite。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM