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
you can use SharedPreferences to save variables within your application. As a example you can use SharedPreferences in a game to save the score/points. In this case if you are dealing with less number of variables i think the best way is SharedPreferences. Hope my answer helped you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With