Search code examples
androidandroid-activitylifecycletimingonpause

why "onPause" is not called in following situation?


By the document, "onPause" is called, when:

when the system is about to start resuming a previous activity.

Compared to "onStop", the difference is:

Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one.

But when I long-press HW-Home key and the "recent apps" shows up, the "onPause" is not called.

At this moment, I can no long able to interact with the original activity, but it is still visible.

I am confused by this situation. Please help to explain.

Thank you very much. BR, Henry


Solution

  • This actually happens because when the Home key is long pressed, there is no activity being launched. The onPause/onStop will only be called if you select one of the apps present in the "Recent Apps" list.

    The docs of onPause() are pretty clear:

    Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.