在android中有什么方法可以在卸载后保留SharedPreferences [英] In android is there any way to preserve SharedPreferences after an uninstall

查看:66
本文介绍了在android中有什么方法可以在卸载后保留SharedPreferences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SharedPreferences 中保留了一些应用程序元数据.每当我卸载应用程序并重新安装它时,SharedPreferences 都会被删除.

I am keeping some application meta data in SharedPreferences. Whenever I uninstall the application and reinstall it, the SharedPreferences are deleted.

有什么办法可以让它保留下来,这样如果用户卸载并重新安装,他们就可以恢复他们的旧数据?

Is there any way to get that to remain, so that if the user does an uninstall and reinstall, they can recover their old data?

推荐答案

您应该将 BackupAgentHelper 添加到您的应用程序.它与 SharedPreferenceBackupHelper 一起将 SharedPreferences 备份到云端(如果设备支持).重新安装应用后,数据会恢复.

You should add a BackupAgentHelper to your app. Together with the SharedPreferenceBackupHelper, it backups the SharedPreferences to the cloud (if the device supports it). When the app is reinstalled the data is restored.

见:

BackupAgentHelper

SharedPreferenceHelper(包含实现它所需的所有代码)

一般备份指南

这篇关于在android中有什么方法可以在卸载后保留SharedPreferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆