I would like to know the scope of
SharedPreferences
. I want to set some variables which can be used in entire application all the time untill unless the application uninstalled by the user. Can I use SharedPreferences to save the value?? I know that I can use database, But I want to know the scope of SharedPreferences, so that I can use SharedPreferences properly. Somebody please help, Thanks in advance.
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).
You can use SharedPreferences
. If you curious about the life of SharedPreferences
then its clear that it will be available for entire life of your application. But keep in mind that All application storage looses data when user clears the application data, so that time SharedPreferences
will also loose the value.
Instead of using db, you can use SharedPreferences
.
Ref : data-storage