android – SharedPreferences的范围

我想知道的范围

SharedPreferences

.除非用户卸载了应用程序,否则我想设置一些可以在整个应用程序中使用的变量.我可以使用SharedPreferences来保存值吗?我知道我可以使用数据库,但我想知道SharedPreferences的范围,以便我可以正确使用SharedPreferences.有人请帮忙,先谢谢.

解决方法:

The SharedPreferences class provides a general framework that allows
you to save and retrieve persistent key-value pairs of primitive data
types. You can use SharedPreferences to save any primitive data:
booleans, floats, ints, longs, and strings. This data will persist
across user sessions (even if your application is killed).

您可以使用SharedPreferences.如果您对SharedPreferences的生命感到好奇,那么很明显它可以在您的应用程序的整个生命周期中使用.但请记住,当用户清除应用程序数据时,所有应用程序存储都会丢失数据,因此SharedPreferences也会丢失该值.

您可以使用SharedPreferences而不是使用db.

参考:data-storage

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...