问题
I'm monitoring an Activity
lifecycle to learn more on it, so I put a Log.d()
call in almost every method of the cycle.
I'm watching particularly the sequence:
[A]onSaveInstanceState() - onPause() - onStop() - onDestroy() - onStart() - [B]onRestoreInstanceState()
See Activity Lifecycle
Switching a 2.2 Froyo emulator with Ctrl-F11 from portrait to landscape I can see one round from [A] to [B].
What is strange to me is that switching back from landscape to portrait I can see two round from [A] to [B].
onSaveInstanceState() - onPause() - onStop() - onDestroy() - onStart() - onRestoreInstanceState()
onSaveInstanceState() - onPause() - onStop() - onDestroy() - onStart() - onRestoreInstanceState()
This is creating me lots of issues in saving/restoring the activity state.
How can it be? Why is it so?
Edited: Using a 2.3.3 Gingerbread emulator the sequence runs only once. But 2.3.3 emulator has a known bug that prevents it from rotating correctly!
回答1:
Rotation in emulator is different from Accelerator rotation. It actually simulates an open-keyboard. These are two different events, which cause two different lify-cycle flows.
回答2:
Its happen some times on emulators, check it on real device, it works properly on real devices.
来源:https://stackoverflow.com/questions/5484108/android-double-lifecycle-sequence-from-landscape-to-portrait