は私のアプリがレイアウトされている方法です。onActivityResult()の前にonResume()が呼び出されていますか?ここ
- onResume()ユーザーは、ユーザーがログインしている場合、ユーザが任意の時にログアウトした場合、彼はアプリ 3を継続して使用することができます
- ログインするように要求されます時間、私は再びログインを促したい
どうすればいいですか?ここで
は私MainActivityである:ここでは
@Override
protected void onResume(){
super.onResume();
isLoggedIn = prefs.getBoolean("isLoggedIn", false);
if(!isLoggedIn){
showLoginActivity();
}
}
は私LoginActivityです:
@Override
protected void onPostExecute(JSONObject json) {
String authorized = "200";
String unauthorized = "401";
String notfound = "404";
String status = new String();
try {
// Get the messages array
JSONObject response = json.getJSONObject("response");
status = response.getString("status");
if(status.equals(authorized)){
Toast.makeText(getApplicationContext(), "You have been logged into the app!",Toast.LENGTH_SHORT).show();
prefs.edit().putBoolean("isLoggedIn",true);
setResult(RESULT_OK, getIntent());
finish();
}
else if (status.equals(unauthorized)){
Toast.makeText(getApplicationContext(), "The username and password you provided are incorrect!",Toast.LENGTH_SHORT).show();
prefs.edit().putBoolean("isLoggedIn",true);
}
else if(status.equals(notfound)){
Toast.makeText(getApplicationContext(), "Not found",Toast.LENGTH_SHORT).show();
prefs.edit().putBoolean("isLoggedIn",true);
}
} catch (JSONException e) {
System.out.println(e);
} catch (NullPointerException e) {
System.out.println(e);
}
}
}
ユーザーが正常にログインした後:問題は、onResume(ある
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "BOOM SHAKA LAKA!",Toast.LENGTH_SHORT).show();
}
}
) onActivityResult()の前に呼び出されるので、ユーザーが正常にログインすると、私の主なアクティビティはnotiになりませんonResume()が最初に呼び出されるために失敗しました。
ログインを促す場所はどこですか?
私はユーザーがログインした後にisLoggedInを設定しています。私の更新されたコードを見てください。何が間違っているかわからない? –
あなたは正しいです、onActivityResult()はonResume()の前に呼び出されています。なぜ私のprefsが間違って読まれているのか分かりませんか? –
は、putBooleanの後にcommit()を追加しました。トリックをしました。 –