Search code examples
androidandroid-activitybackandroid-lifecycle

Back key infinitely loops back to same activity


I am programming an Android application and have a curious issue.

My application has a LoginActivity that defines the filter for launch events. As soon as login is complete, it starts the "Home" activity using startActivity(new Intent(LoginActivity.this, HomeActivity.class)) and stops the LoginActivity using finish().

The HomeActivity is a simple dashboard with notifications, overriding onCreate and onStart. Also it updates the some content icons using an AsyncThread.

The problem is this: If I hit the Home-Button to exit my app and then use the "recent" menu (holdpress the Android-Home Button) to reopen it, the back-key is 'broken' in my app: Pressing it will not finish the HomeActivity, but instead loop back to the same activity:

Meaning ... HomeActivity <- HomeActivity <- HomeActivity <- HomeActivity ...

I have not used any hacks to override the backstack or back key behaviour. Anyone got a clue what the cause of this may be?

TIA, Patrick


Solution

  • Maybe your login activity detects that login is complete and sends you immediately back to your home activity. That should be visible from the log (ActivityManager, START intent ...)

    In that case it may be a good idea to play with the backstack