-
Couldn't load subscription status.
- Fork 10
Preference Tutorials
Mohit Rajput edited this page Jan 27, 2019
·
1 revision
This library is used to make storing and retrieving values from the shared preference easy.
The following method returns the instance of preference utils-
SharedPreferenceUtils sharedPreferenceUtils = SharedPreferenceUtils.getInstance(context);SharedPreferenceUtils returns the singleton instance which is used to store and retrieve.
SharedPreferenceUtils.getInstance(context).saveBoolean("is_logged_in", true);boolean isLoggedIn = SharedPreferenceUtils.getInstance(context).getBoolean("is_logged_in");To retrieve with default values-
boolean isLoggedIn = SharedPreferenceUtils.getInstance(context).getBoolean("is_logged_in", false);To clear a value- SharedPreferenceUtils.getInstance(context).clear("is_logged_in");
To clear all values from preference-
SharedPreferenceUtils.getInstance(context).clear();Preference utility has methods for all primitive data types and String.
Presented by Our Techno Bytes