Android programs disable automatic screen lock and screen flip on mobile phones

Source: Internet
Author: User

During Android development, some programs do not need to automatically lock the screen when running, that is, keep the background light of the system on normally, to prevent exceptions during program execution, you only need to add the following statement to the oncreate () method when creating an activity.

Getwindow (). addflags (windowmanager. layoutparams. flag_keep_screen_on );

In addition, if the screen is flipped during the program running, the android system automatically changes the screen direction. At this time, the system will re-call the oncreate () method to create the activity, therefore, during program development, you must pay attention to saving the scene and switching the screen width to width ratio. If you do not need this function, you can go to androidmanifest. modify the XML file by adding the following statement to each activity.

Android: screenorientation = "portrait" // portrait indicates that the screen is vertical.

Eg:

<Activity Android: Name = "mainactivity"

Android: Label = "@ string/hello"

Android: screenorientation = "portrait">

</Activity>

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.