Android-Problems with locking the horizontal screen: android locks the horizontal screen

Source: Internet
Author: User

Android-Problems with locking the horizontal screen: android locks the horizontal screen

Android Developers should lock the horizontal screen as needed by the customer, and share the problems encountered during this period with you:

First, set in the project list file:Android: screenOrientation = "landscape" // lock the landscape

Android: configChanges = "keyboardHidden | orientation" // avoid repeated execution lifecycles

However, if the screen is still displayed in portrait mode, you need to add the code to mainActivity:

@ Override
Public void setRequestedOrientation (int requestedOrientation ){
Return;
}

@ Override
Public void onConfigurationChanged (Configuration newConfig ){
// TODO Auto-generated method stub
Super. onConfigurationChanged (newConfig );
}

I really thought this would be enough. When the mobile phone automatically locks the screen, he actually calls onDestroy (), which leads to re-executing the lifecycle during unlocking. Baidu knows:

The code in the project list file:

Android: configChanges = "keyboardHidden | orientation" changed:

Android: configChanges = "keyboardHidden | orientation | screenSize"

This is really done, and I hope to help you!

Related Article

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.