我试图在两个不同的键上保存两个布尔值,但是每次我在键中保存值时,它只用最后一个值覆盖键。
下面是保存值的函数调用
AssignRegistrationFun manage =
new AssignRegistrationFun(getApplicationContext());
manage.ChangeDataState(false,true);
下面是在 if 条件下检查数据状态的函数调用......在这个函数调用中,即使我将第一个值设置为 false,它也会返回 true
if(manage.checkDataChanged("External"))
下面是带有类详细信息的函数定义
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class AssignRegistrationFun {
SharedPreferences pref;
Editor editor;
Context _context;
int PRIVATE_MODE = 0;
private static final String PREF_NAME ="Tester";
private static final String EXTERNAL_DATA = "true";
private static final String INTERNAL_DATA = "true";
public AssignRegistrationFun(Context context){
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
public void ChangeDataState(boolean EX_state,boolean IN_state){
editor.putBoolean(EXTERNAL_DATA,EX_state);
editor.putBoolean(INTERNAL_DATA,IN_state);
editor.commit();//even editor.apply() not works
}
public boolean checkDataChanged(String type){
if(type.equals("External"))
return pref.getBoolean(EXTERNAL_DATA,false);
else
return pref.getBoolean(INTERNAL_DATA,false);
}
}
请帮助我提前谢谢...