Object POBSharedPreferenceUtil
-
- All Implemented Interfaces:
public class POBSharedPreferenceUtilThe object/util class manage the shared preference for OpenWrap SDK.
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringTAGpublic final static POBSharedPreferenceUtilINSTANCE
-
Method Summary
Modifier and Type Method Description final static Unitinit(Context context)Initialize the shared preference by getting the default shared preference and fetch a temp value so that shared preference loads up the file and caches it. final static StringgetStringFromSharedPreference(Context context, String key, String defaultValue)Returns the String value saved in app's default sharedPreference for a key else return the provided default value. final static IntegergetIntegerFromSharedPreference(Context context, String key)Returns the Integer value if saved in app's default sharedPreference for given key. final static SharedPreferencesgetDefaultSharedPreference(Context context)Returns the default shared preference. final static SharedPreferencesgetNamedSharedPreference(Context context, String name)Returns the named shared preference. final static <T extends Any> UnitwriteValueInSharedPreference(Context context, String prefName, String key, T value)Use to store value on shared preference with the provided key and value passed. -
-
Method Detail
-
init
final static Unit init(Context context)
Initialize the shared preference by getting the default shared preference and fetch a temp value so that shared preference loads up the file and caches it. It helps in reducing the time taken to fetch the value from shared preference going further in the same app session.
The key doesn't matter as SharedPreference internally reads the whole file once
- Parameters:
context- Application context
-
getStringFromSharedPreference
final static String getStringFromSharedPreference(Context context, String key, String defaultValue)
Returns the String value saved in app's default sharedPreference for a key else return the provided default value.
- Parameters:
key- Key against which value is saveddefaultValue- Default value to be return, if not found- Returns:
string value if present in default shared preference, else return provided defaultValue
-
getIntegerFromSharedPreference
final static Integer getIntegerFromSharedPreference(Context context, String key)
Returns the Integer value if saved in app's default sharedPreference for given key. It returns null, if key is not found.
- Parameters:
key- Key against which value is saved- Returns:
integer value if present in default shared preference, else return provided defaultValue
-
getDefaultSharedPreference
final static SharedPreferences getDefaultSharedPreference(Context context)
Returns the default shared preference.
- Parameters:
context- to get the default shared preferences.- Returns:
Instance of {@link SharedPreferences}
-
getNamedSharedPreference
final static SharedPreferences getNamedSharedPreference(Context context, String name)
Returns the named shared preference.
- Parameters:
context- to get the default shared preferences.name- of the shared preference- Returns:
Instance of SharedPreferences
-
writeValueInSharedPreference
final static <T extends Any> Unit writeValueInSharedPreference(Context context, String prefName, String key, T value)
Use to store value on shared preference with the provided key and value passed. The value will be stored in the POBCommonConstants.SHARED_PREF_NAME named SharedPreferences
- Parameters:
context- Context to get the reference of SharedPreferencesprefName- Name of the shared preference to write the valueskey- Key for storing value in SharedPreferencesvalue- Value stored for passed key
-
-
-
-