I have a weird issue that happens on Android 10, when I start new landscape activity, the activity below will recreate.
Assume there're two Activity
classes:
ActivityA: orientation = unspecified
ActivityB: orientation = force landscape, full screen, opaque
If I start ActivityB
from ActivityA
, the logs of lifecycle event:
D/ActivityA: onPause() called
D/ActivityB: onCreate() called
D/ActivityB: onStart() called
D/ActivityB: onResume() called
D/ActivityA: onStop() called
D/ActivityA: onDestroy() called
D/ActivityA: onCreate() called
D/ActivityA: onStart() called
D/ActivityA: onResume() called
D/ActivityA: onPause() called
D/ActivityA: onStop() called
Can clearly see that ActivityA
is recreated, moreover somehow ActivityA#onResume
is called after ActiviyB#onResume
??
Okay, so now we have ActivityB
on top of the stack, then I press back button:
D/ActivityB: onPause() called
D/ActivityA: onStart() called
D/ActivityA: onResume() called
D/ActivityA: onPause() called
D/ActivityA: onStop() called
D/ActivityA: onDestroy() called
D/ActivityA: onCreate() called
D/ActivityA: onStart() called
D/ActivityA: onResume() called
D/ActivityB: onStop() called
D/ActivityB: onDestroy() called
ActivityA
is recreated again?
As I see in my device, there's an animation that ActivityA
rotates into landscape mode before ActivityB
becomes visible, and when ActivityB
exits, ActivityA
again rotates back to portrait mode. This behavior may cause ActivityA
recreate again and again.
It messes up a lot, do you know how to prevent ActivityA
recreate on this case, or this is a bug of Android itself?
from Android 10 - Weird activity lifecycle
No comments:
Post a Comment