0
發送sharedpreference 此的數據是用於通信接口無法從內部片段中的sharedPrference中檢索數據?
@Override
public void saveBMI(String d, String r, String f_r) {
sharedPreferences=getSharedPreferences("userBMI",Context.MODE_PRIVATE);
editor=sharedPreferences.edit();
editor.putString("CheckDate",d);
editor.putString("BmiResult",r);
editor.putString("BmiWeight",f_r);
editor.commit();
}
該方法我使用用於從共享的偏好將數據發送到另一片段
@Override
public void showBMI() {
if(sharedPreferences.contains("CheckDate"))
{
c_d=sharedPreferences.getString("CheckDate","");
}
if(sharedPreferences.contains("BmiResult"))
{
bmi_res=sharedPreferences.getString("BmiResult","");
}
if(sharedPreferences.contains("BmiWeight"))
{
bmi_w=sharedPreferences.getString("BmiWeight","");
}
//here i want to send the data to another fragment ...???
}
呼叫碼)方法... –
哪個代碼拋出情人 – Manish
共享偏好應該經由單獨的對象進行訪問。如果您每次創建新對象,則不會從共享首選項獲取數據。 –