Method One:
Screenorientation = Application.getresources (). GetConfiguration (). Orientation;
Method Two:
Screenorientation = Activity.getrequestedorientation (); Gets the direction of the current activity
Dynamic setting Screen:
Setrequestedorientation (activityinfo.screen_orientation_portrait);
Life cycle:
Toggle Screen
(1) No configchanges
Oncreate-->
Onstart-->
Onresume-->
----------Switch--------
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
-----------Switch--------
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
(2) Modify the Androidmanifest.xml, add the activity android:configchanges= "orientation", perform step 3
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
Perform step 4 again to find that the same information is no longer printed, but one line is printed more onconfigchanged
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
Onconfigurationchanged-->
(3) Change to android:configchanges= "Orientation|screensize|keyboardhidden" (sdk>13 need to add screensize), perform step 3, Just print onconfigchanged
Onconfigurationchanged-->
Perform step 4
Onconfigurationchanged-->
Onconfigurationchanged-->
Summarize:
1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice
2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
2, set the activity android:configchanges= "Keyboardhidden", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
3, set the activity android:configchanges= "Orientation|screensize|keyboardhidden", the screen will not recall the various life cycle, Only the Onconfigurationchanged method is executed
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/71/7D/wKiom1XRrrWgXnUZAAOWdTGTP60333.jpg "title=" QQ picture 20150817175201.png "alt=" Wkiom1xrrrwgxnuzaaowdtgtp60333.jpg "/>
Android Get Settings Screen portrait