Android “single top” launch mode and onNewIntent method

Did you check if onDestroy() was called as well? That’s probably why onCreate() gets invoked every time instead of onNewIntent(), which would only be called if the activity is already existing.

For example if you leave your activity via the BACK-button it gets destroyed by default. But if you go up higher on the activity stack into other activities and from there call your ArtistActivity.class again it will skip onCreate() and go directly to onNewIntent(), because the activity has already been created and since you defined it as singleTop Android won’t create a new instance of it, but take the one that is already lying around.

What I do to see what’s going on I implement dummy functions for all the different states of each activity so I always now what’s going on:

@Override
public void onDestroy() {
    Log.i(TAG, "onDestroy()");
    super.onDestroy();
}

Same for onRestart(), onStart(), onResume(), onPause(), onDestroy()

If the above (BACK-button) wasn’t your problem, implementing these dummies will at least help you debugging it a bit better.

Leave a Comment