Proper Way of Handling an Orientation Change in Android

What is the proper way of handling an orientation change in Android? When I researched this question there are two methods that came up.

1st Method Use the methods onSaveInstanceState(Bundle savedInstanceState) and onRestoreInstanceState(Bundle savedInstanceState) to store and restore your Activity after being killed by the Android OS after the orientation change.

2nd Method Added android:configChanges="orientation|keyboardHidden" to your AndroidManifest.xml so the Activity will not be destroyed when the orientation is changed.

I have tried both methods and they both work, however the first method takes a lot longer to implement. While I do see posts about the 2nd method, I want to know if this is an "accepted" and "proper" way of handling an orientation change. And what are the advantages and disadvantages for each method? Thanks!


The second method will not allow you to do certain orientation specific stuff such as load a different layout for when the screen is rotated or not (I'm thinking of resource suffixes here). I have not encountered any other ill effects, however the docs state that: "Using this attribute should be avoided and used only as a last-resort."

More info here: http://developer.android.com/guide/topics/resources/runtime-changes.html


请参阅http://developer.android.com/guide/topics/resources/runtime-changes.html,他们在这里解释两种方法并给出优缺点和最佳解决方案。

链接地址: http://www.djcxy.com/p/8108.html

上一篇: 如何使用$ ORIGIN和suid应用程序?

下一篇: 在Android中处理方向变化的正确方法