Last active
August 29, 2015 14:27
-
-
Save Sirelon/a7c368829c95c0a30db4 to your computer and use it in GitHub Desktop.
Simple class which wrapper into self SharedPrefernce object and work with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sirelon; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
/** | |
* @author romanishin | |
* @since 21.08.15. | |
*/ | |
public class AppSettings { | |
private static final String PREF_NAME = "{prefernceName}}"; | |
private final SharedPreferences mPref; | |
public AppSettings(Context context) { | |
this.mPref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); | |
} | |
public void putString(String key, String value) { | |
mPref.edit().putString(key, value).apply(); | |
} | |
public void putInt(String key, int value) { | |
mPref.edit().putInt(key, value).apply(); | |
} | |
public void putLong(String key, long value) { | |
mPref.edit().putLong(key, value).apply(); | |
} | |
public boolean exist(String key) { | |
return mPref.contains(key); | |
} | |
public String getString(String key) { | |
return mPref.getString(key, ""); | |
} | |
public int getInt(String key) { | |
return mPref.getInt(key, -1); | |
} | |
public long getLong(String key) { | |
return mPref.getLong(key, -1); | |
} | |
public void remove(String key){ | |
mPref.edit().remove(key).apply(); | |
} | |
public void clearAll() { | |
mPref.edit().clear().apply(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment