2

My app has two activities MAIN and LOGIN.

The workflow of my app is as follows with MAIN being the launcher

 MAIN - If user logged in, show MAIN
 MAIN - If user NOT logged in, show LOGIN and close finish MAIN

Below is a scenario where this works fine.

 User launches the app -> sees LOGIN screen
 User logs in, sees the MAIN screen
 User presses back button on phone, sees the phone's screen again (NOT the LOGIN screen again)   

Below is a scenario where this does not work fine.

 User launches the app -> sees LOGIN screen
 Presses middle button on the phone to send app to background
 User launches the app again -> sees the LOGIN screen (here another instance of the login screen is being created...)
 User logs in, sees the MAIN screen
 User presses back button on phone, sees the LOGIN screen again!

How can I fix this scenario, so that doesn't matter if the middle button on the phone is pressed or not pressed, there is always only one instance of login screen?

Here is my code:

MAIN

       @Override
       public void onStop() {
          super.onStop();
          finish();
       } 

       if (TextUtils.isEmpty(authToken)) {
            Intent login = new Intent(getApplicationContext(), LoginActivity.class);
            startActivityForResult(login, LOGIN_ACTIVITY);
            finish();
        }

LOGIN

    mAccountManager.addAccountExplicitly(account, accountPassword, null);
    mAccountManager.setAuthToken(account, authtokenType, authtoken);
    mAccountManager.setPassword(account, accountPassword);
    startActivity(new Intent(getApplicationContext(), MainActivity.class));

update

Lal
  • 14,726
  • 4
  • 45
  • 70
birdy
  • 9,286
  • 24
  • 107
  • 171

0 Answers0