Android:仅一次变量存储
我有一个应用程序,仅在用户第一次启动该应用程序时才会显示欢迎窗口。将此布尔变量(即“isFirstTime”)存储到手机存储的最佳方法是什么?我应该使用共享首选项还是内部存储?
文档说,如果我使用内部存储,我的“首选项”文件将在卸载时自动删除,这非常方便。
我想要一个干净、简单且快速的解决方案。
I have an appliaction which will show a welcome window only the first time the user starts the app. What would be the best way to store this boolean variable (i.e. "isFirstTime") to phone storage? Should I use Shared Preferences or Internal Storage?
The docs say that if I use Internal Storage my "preference" file will automatically get removed upon uninstallation which is quite handy.
I want a clean, simple and fast solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我建议使用共享首选项。基本上,您可以将共享首选项的键设置为“isFirstTime”,并将布尔类型设置为 false。然后在您的主要活动中执行以下操作:
如果找不到 isFirstTime 将为您提供 true,允许您根据结果执行 if 语句。
Yes, I'd recommend using Shared Preferences. Basically you could put a shared preference with a key of "isFirstTime" and a type of boolean set to false. Then in your main activity do something like:
This, if it can't find isFirstTime will give you true, allowing you to do an if-statement based on the result.
我同意 SharedPreferences 可能是您正在寻找的最“干净、简单和快速的解决方案”。卸载应用程序时,SharedPreferences 也会被删除。
是共享首选项删除应用程序时与该应用程序关联的删除?
I agree that SharedPreferences would probably be the most "clean, simple, and fast solution" that you are looking for. SharedPreferences are also deleted when the application is uninstalled.
Are the shared preferences associated with the App deleted when the app is removed?
SharedPreferences
是您的最佳选择。SharedPreferences
are your best option for this.