我2个机器人应用通信throught一个AIDL文件:机器人:SharedPreferences未更新
应用程序A < == AIDL ==>应用B(服务)
应用A调用的应用的方法B(服务)返回一些JSON信息。但是,如果用户未登录到应用程序B,则返回空值。
(在应用程序B服务)
//first : get info
SharedPreferences mPrefs = getSharedPreferences(Consts.SP_NAME, MODE_PRIVATE);
String userId = mPrefs.getString(Consts.PREFS_USER_ID, "");
String userPass = mPrefs.getString(Consts.PREFS_USER_PASS, "");
//then check is valid (remote server)
if (dao.exist (userId, userPass)){
return "MY_JSON_INFO" ;
}else{
return false;
}
如果返回null, “登录”,在应用B的活动是从应用A.
(Aplication A)
if(json == null){
Intent intent = new Intent("jp.app.LOGIN_ACTIVITY");
startActivity(intent);
}
推出用户登录(应用程序B),数据保存在SharedPreferences(应用程序B)中,活动关闭(返回到应用程序A)。
SharedPreferences mPrefs = a.getSharedPreferences(Consts.SP_NAME, MODE_PRIVATE);
Editor prefsEditor = mPrefs.edit();
prefsEditor.putString(Consts.PREFS_USER_ID, id);
prefsEditor.putString(Consts.PREFS_USER_PASS, pass);
prefsEditor.commit();
当重新尝试调用应用程序B的方法时,几秒前保存的登录信息不可用,并返回null。
我尝试过没有成功prefsEditor.apply()。
如果我重新启动应用程序B,登录数据将被载入....
请让我知道,如果需要进一步的信息。 谢谢
Editor prefsEditor = prefsEditor.commit();将这些行更改为\ prefsEditor.commit(); – Avijit
我已更新我的消息,对不起 – johann