Android Get Settings Screen portrait

Source: Internet
Author: User

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:

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.