androidactivity-lifecycleactivity-stackactivity-state

Best way to handle activity state


I'm making an app that shows another activity when I correctly login however in the home screen when I pressed back and then returned to the app the login activity showed.

I was able to avoid this overriding the onBackPressed this way:

public void onBackPressed()
        moveTaskToBack(true);
    }

Is this the best way to do it? Is there a more proper way to keep the state of the application when I exit it?


Solution

  • In your login activity after starting intent call finish()

    finish destroy your activity and avoid to run it again automatically.