我是改造的新手,我希望能够保存令牌,该令牌在用户打开应用程序时会保留,并在用户注销应用程序时删除,例如firebase所做的操作
答案 0 :(得分:0)
为您的翻新回调执行此操作.....
call.enqueue(new Callback<AllResponseData>() {
@Override
public void onResponse(Call<AllResponseData> call, Response<AllResponseData> response) {
pDialog.dismiss();
if (response.isSuccessful()) {
ResultBody result = (ResultBody) response.body();
if (result.isSuccess()) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("token", result.getToken()).commit();
// other stuff over here
} else
Log.d("sushildlh",result.getMessage());
} else
Toast.makeText(context, response.message(), Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<AllResponseData> call, Throwable t) {
pDialog.dismiss();
}
});
在注销按钮上执行此操作.....
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("token", "").commit()
// other stuff over here