Is onPause() called when user closes the app from recents

1.1k views Asked by At

I read a lot about activity lifecycle but I cannot find a simple answer. Let's assume someone is pressing Switch apps hardware button. When app is switched to a different app onPause() is guaranteed to be called. Also pressing Back (to close the app) or Home will invoke onPause().

But here is the question. When I open app list where I can switch between apps will just the button click invoke onPause()? I mean is just clicking Switch apps invokes onPause()?

It's not clear to me and the documentation doesn't describe that case.

EDIT: I was wrong saying that onPause() is not invoked after the button click only. I'm sorry.

6

There are 6 answers

0
Steven_BDawg On BEST ANSWER

Based on the Activity page, onPause() will be called. Any app that is in the foreground will call onPause() the moment the user pulls up the app list to start swiping away apps.

2
Sharp Edge On

Let's assume someone is pressing Switch apps hardware button. onPause() will not be called until someone choses a different app from the list.

Are you sure when you press the button which lets you choose other apps doesn't call onPause() until you choose an app ? I doubt that.

0
Galax On

The application will call the onPause method initially right before the list of apps appears, but not when it is swiped away (or even when another app is selected)

7
Arn ZXY On

Yes onPause() is always called before onDestroy(). It goes like this: onPaused() --> onStop() --> onDestroy()

enter image description here

Always follow the direction of the arrows. Those methods go in a consecutive manner no matter what. A method like onStop() is always executed after onPause() and before onDestroy() no matter the situation.

0
Joseph Roque On

The activity lifecycle is always called in the order given in the documentation. Meaning onCreate > onStart > onResume > onPause > onStop > onDestroy. There can be some repeats of calls, such as going back and forth between onResume and onPause as the activity comes to the foreground and moves to the background, but they are always in this order. Meaning, if you're certain onDestroy is being called, then you can be certain onPause and onStop have been called.

1
Steve On

Actually the OP is correct. I was shocked as well. Forever, showing the Recent Apps would trigger the pause. Recent changes of Android 11 don't pause until the other app is selected. This means that on Android 11 apps visible on Recent Apps are live, not thumbnails.

If you were to show a privacy screen on pause, and dismiss on resume, you will see the privacy on the thumbnail on older OS but 11 you will see the privacy flash onto the thumb as it animates away once the other app is selected.