Android - Double lifecycle sequence from landscape to portrait

六月ゝ 毕业季﹏ 提交于 2019-12-10 11:49:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!