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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With