import android.content.Context; import android.content.SharedPreferences; public class UserDefaults { SharedPreferences preferences ; public static UserDefaults getInstance(Context context){ UserDefaults instance = new UserDefaults(); instance. preferences = context.getSharedPreferences( "MyPreferences" , Context. MODE_PRIVATE ); return instance; } public void setString(String key, String value){ SharedPreferences.Editor editor = preferences .edit(); editor.putString(key, value); editor.commit(); } public String getString(String key){ return preferences .getString(key, "" ); } }