0

While reading a couple of answers in this post, the following passage from this answer had me in a state of confusion:

onPause(): Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume(). When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A's onPause() returns, so be sure to not do anything lengthy here.

The above seems to suggest the following ordering of events:

  1. B is launched in front of A;
  2. onPause() is called on A;
  3. onPause() returns;
  4. B is created.

What I don't understand pertains to how can the first event precede the fourth, i.e., how can B be launched and appear in front of A before being created in the first place.

Mohammed s
  • 17
  • 6
Mehdi Charife
  • 722
  • 1
  • 7
  • 22
  • 1
    A better phrasing of the confusing sentence might be: "When activity B is *requested to be* launched in front of activity A, this callback will be invoked on A". – CommonsWare Feb 11 '23 at 14:16
  • @CommonsWare So actually `onPause()` is called on A before B appears in the foreground? – Mehdi Charife Feb 11 '23 at 14:17
  • 1
    To be honest, I have not tried checking at that level in many years. You might want to run your own experiments! I am simply used to how Google tends to write their documentation and how to try to "patch up" confusing phrasing. – CommonsWare Feb 11 '23 at 14:34
  • 1
    1- You request to launch B. 2- B is not launched yet and not visible too. 3- `onPause` of A is called. 4- `onPause` is finished 5- B is now launched and visible. – Armin Feb 11 '23 at 18:51
  • 1
    To get the idea you can add some logs to Both A and B lifecycle methods like `onCreate`, `onStart`, ... to see the order of calling these methods. – Armin Feb 11 '23 at 18:54

0 Answers0