我想知道的范围
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