Android lifecycle inversion

38 Views Asked by At

I encountered somewhat confusing situation, so I wanted to ask a principle behind it.

scenario : I have two activities A and B. A is a launcher activity and A starts B activity. I wanted to finish B activity and start B again. the situation I called confusing starts here. the normal scenario is I assume

  1. B-onPause
  2. A-onStart
  3. A-onResume
  4. B-onStop
  5. B-onDestroy --> starts B
  6. A-onPause
  7. B-onCreate
  8. B-onStart
  9. B-onResume
  10. A-onStop

but when I simulate this scenario as fast as possible(with my finger), this order does not remain. like this

  1. B-onPause
  2. A-onStart
  3. A-onResume
  4. A-onPause
  5. B-onCreate
  6. B-onStart
  7. B-onResume
  8. A-onStop
  9. B-onStop
  10. B-onDestroy

I know that if activity A starts Activity B, the following order is fixed one (A-onPause -> B-onCreate -> B-onStart -> B-onResume). Except resume and pause, another lifecycle callbacks are undeterministic?

I can simultate this on low-spec android device, but not on regular mid,high-spec device.

so one line question is : when finishing and reopening activity, onStop and on Destroy can be done after onResume callback?

thanks in advance and sorry for bad english :)

1

There are 1 best solutions below

0
David Wasser On BEST ANSWER

onStop() and onDestroy() are basically "cleanup" operations that can be performed at any time after the Activity is paused. You absolutely can not rely on these being called at any specific time.