-1
我需要使用會話到我的應用程序,所以我創建了一個名爲SessionManager
的java類,在這裏我初始化了會話,但是當我創建了三個不同的獲取函數並且我使用它們時,會話的值已被覆蓋。 。如何從SharedPreferences獲取數據?
我funtions是:
public String getBname() {
return pref.getString(BREAKFAST_NAME,null);
}
public String getBcalories() {
return pref.getString(BREAKFAST_CALORIES,null);
}
public String getBquantity() {
return pref.getString(BREAKFAST_QUANTITY,null);
}
,我打電話給他們以這樣的方式
String name=sessionDay.getBname();
String calories=sessionDay.getBcalories();
String quantity=sessionDay.getBquantity();
etFBreakFast.setText("Name: " + name + "\n" + "Calories: " + calories + "\n" + "Quantity: " + quantity);
那麼是什麼問題?
您應該閱讀以下內容的Shared Preferences部分:http://developer.android.com/guide/topics/data/data-storage.html –