Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scope of SharedPreferences

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.

like image 507
Jithu Avatar asked Dec 12 '22 14:12

Jithu


2 Answers

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

like image 72
Pankaj Kumar Avatar answered Dec 21 '22 10:12

Pankaj Kumar


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.

like image 27
posha Avatar answered Dec 21 '22 09:12

posha