Three ways Android keeps the screen solid

Source: Internet
Author: User

A long time did not write blog, and recently to achieve similar functions, each time Baidu to find is not very convenient, or in their own blog record a pen!

There are three types of methods:

1. Apply for a bright screen lock

PM = (PowerManager) context.getsystemservice (Context.power_service);
Get the Power Manager object
WL = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.full_wake_lock, "TEST");

Wl.acquire ();

Release when not in use

This thing is deep water, we need to take time to study, also including CPU wake lock and so on

2. Through the Flag property of window

GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_ SCREEN_ON);
Setcontentview (r.layout.xmltext);//must be before this

This property is actually Google's alternative to Method 1.

3. Recommended use, this method is the simplest, no need to modify the code

Android:keepscreenon= "true"

As long as the control basically has this property, the code can also be set

Three ways Android keeps the screen solid

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.