Est onResume() est appelée avant onActivityResult()?

Ici est de savoir comment mon application est posé:

  1. onResume() de l'utilisateur est invité à vous connecter à
  2. Si l'utilisateur se connecte, il peut continuer à utiliser l'application
    3. Si l'utilisateur se connecte à n'importe quel moment, je veux vous invite vous connecter à nouveau

Comment puis-je y parvenir?

Voici mon MainActivity:

@Override
    protected void onResume(){
        super.onResume();

        isLoggedIn = prefs.getBoolean("isLoggedIn", false);

        if(!isLoggedIn){
            showLoginActivity();
        }
    }

Voici mon 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);
            }
        }
    }

Après que l'utilisateur s'est connecté avec succès dans:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(getApplicationContext(), "BOOM SHAKA LAKA!",Toast.LENGTH_SHORT).show();
        }
    }

Le problème est, onResume() est appelée avant onActivityResult() ainsi, lorsque l'utilisateur s'est connecté avec succès dans, mon activité principale n'est pas notifié, car onResume() est appelé en premier.

Où est le meilleur endroit pour demander de connexion?

InformationsquelleAutor Sheehan Alam | 2010-11-23