Created
February 16, 2016 17:12
-
-
Save abbas-oveissi/455e44d2ca6b30509fd0 to your computer and use it in GitHub Desktop.
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
import android.content.Context; | |
import android.content.SharedPreferences; | |
//usage: | |
// SettingsManager sm=new SettingsManager(getApplicationContext()); | |
// String firstName=sm.getFirstName(); | |
public class SettingsManager { | |
SharedPreferences pref; | |
SharedPreferences.Editor editor; | |
Context _context; | |
int PRIVATE_MODE = 0; | |
private static final String PREFER_NAME = "SettingData"; | |
private static final String FIRST_NAME = "firstname"; | |
private static final String LAST_NAME = "lastname"; | |
public SettingsManager(Context context){ | |
this._context = context; | |
pref = _context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE); | |
editor = pref.edit(); | |
} | |
public void setFirstName(String firstName){ | |
editor.putString(FIRST_NAME, firstName); | |
editor.commit(); | |
} | |
public String getFirstName(){ | |
return pref.getString(FIRST_NAME,""); | |
} | |
public void setLastName(String lastname){ | |
editor.putString(LAST_NAME, lastname); | |
editor.commit(); | |
} | |
public String getLastName(){ | |
return pref.getString(LAST_NAME,""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment