Я передаю значение строки jsonobject для своих общих настроек и совершу его. Но, получая это, возвращается значение по умолчанию.Строка JSONObject не сохраняется в sharedpreferences
Для сдачи:
public void new_putMultipleProfileData(String got_multiple_json_data){
Editor editor=app_prefs.edit();
editor.putString(NEW_TESTING_PIC_ID, got_multiple_json_data);
editor.commit();
}
Для получения:
public String new_getMultipleProfileData(){
return app_prefs.getString(NEW_TESTING_PIC_ID,"0");
}
Полное Предпочтение Helper Класс:
public class PreferenceHelper {
private final String PREF_NAME = "Testing_xyz";
private SharedPreferences app_prefs;
//For Testing
public static final String NEW_TESTING_PIC_ID = "testing";
private Context context;
public PreferenceHelper(Context context) {
app_prefs = context.getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE);
this.context = context;
}
public void new_putMultipleProfileData(String got_multiple_json_data){
AppLog.Log("new_data_80503","got_multiple_json_data "+got_multiple_json_data);
Editor editor=app_prefs.edit();
editor.putString(NEW_TESTING_PIC_ID, "hello");
editor.commit();
}
public String new_getMultipleProfileData(){
AppLog.Log("new_data_80503","new_getMultipleProfileData "+app_prefs.getString(NEW_TESTING_PIC_ID,"0"));
return app_prefs.getString(NEW_TESTING_PIC_ID,"0");
}
}
как вы Инициирование app_prefs? – Pr38y
@ Pr38y private SharedPreferences app_prefs; –
@ Pr38y public PreferenceHelperClass (контекст контекста) { app_prefs = context.getSharedPreferences (PREF_NAME, Context.MODE_PRIVATE); this.context = context; } –