Screen orientation changes occur in many applications, but what happens when things change?
Let's write an app to test it.
Here's the code: http://download.csdn.net/detail/edwardwayne/8594291
We wrote a few important stages of the Android life cycle oncreate,onresume,onstart,ondestory,onstop approach in mainactivity
Calling the Toast method in it tells us that there are no triggers at these stages.
In addition we rewrite onsaveinstancestate () and onrestoreinstancestate ()
In them, as well. Add Toast Hints
This time we enter the app, rotating the phone we will find in turn OnStop,onsaveinstancestate, Ondestroy,oncreate,onstart, Onrestoreinstancestate, Onresume
We can understand that by default, changing the direction app will cycle through the life cycle, which in the test will be easier to cause the app to crash.
In order to avoid this situation, we can join in the activity of manifest
android:configChanges="orientation|screenSize|keyboardHidden"
And we joined in the mainactivity.
public void onconfigurationchanged (Configuration newconfig) {//TODO auto-generated method Stubsuper.onconfigurationchanged (Newconfig); if (newconfig.orientation = = Configuration.orientation_landscape) { Toast.maketext (This, "landscape", Toast.length_short). Show (); else if (newconfig.orientation = = configuration.orientation_portrait) {Toast.maketext (this, "PORTRAIT", toast.length_ Short). Show ();}}
This time we change the direction of the phone, we will be the birth, the app has no cycle life cycle, but triggered the onconfigurationchanged method.
As for the function of Keyboardhidden is to hide the keyboard after rotating the mobile phone direction.
What happens when the Android screen is switched vertically