-1

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.

koras
  • 1,107
  • 2
  • 13
  • 28
  • @downvoter care to comment what was wrong with my answer ? that you downvoted immediately within milli seconds of my posting it. – Sharp Edge Jun 18 '15 at 13:11
  • @Sharpedge tell me about it. -_- – Galax Jun 18 '15 at 13:13
  • "onPause() will not be called until someone choses a different app from the list" This is false, atleast on my device onPause is called when the button is pressed to show the list of apps. – M4rtini Jun 18 '15 at 13:16

6 Answers6

2

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.

Steven_BDawg
  • 796
  • 6
  • 21
0

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.

Sharp Edge
  • 4,144
  • 2
  • 27
  • 41
0

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)

Galax
  • 367
  • 1
  • 13
0

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.

Arn ZXY
  • 77
  • 1
  • 8
  • `onPause()` is the only one you can guarantee will be called. `onStop()` and `onDestroy()` may not be. – Steven_BDawg Jun 18 '15 at 13:21
  • I thought he meant he swiped away the app itself... not other apps – Arn ZXY Jun 18 '15 at 13:26
  • "But here is the question. When I open app list where I can switch between apps and I will swipe the app away to close it, will onPause() be called? I know that onDestroy() is always called in that case but is onPause() always called before onDestroy() in that case?" - By what he means here I am completely right. He means that he swipes the app itself away. – Arn ZXY Jun 18 '15 at 13:29
  • `onPause()` will be called. If you swipe away the app, `onStop()` and `onDestroy()` actually may not be called. Note the cutoff line that goes left from `onPause()`. – Steven_BDawg Jun 18 '15 at 13:56
  • http://developer.android.com/images/training/basics/basic-lifecycle-paused.png. Have a look at this other one. The cutoff line is not there. In all my experience I have never had apps not go through onStop() and onDestroy(). If you could let me know of a case when that happens that would be great – Arn ZXY Jun 18 '15 at 14:09
  • That's great and all, but if you go to the Activity page I linked in my answer, it explains it. Basically, pre-Honeycomb, `onStop()` and `onDestroy()` may not be called before an app is killed. From Honeycomb and onward, an app is not labeled as `killable` until `onStop()` has been called and completed. – Steven_BDawg Jun 18 '15 at 14:41
  • Ok that makes more sense now. So killing of the app in onPause() is not guaranteed anymore after Honeycomb. The methods following it might not execute. Thank you for pointing that out. – Arn ZXY Jun 18 '15 at 14:57
0

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.

Joseph Roque
  • 5,066
  • 3
  • 16
  • 22
0

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.

Steve
  • 1