Android program running screen keeps on

Source: Internet
Author: User

Keep the screen on when running the program.

Powermanager. wakelock must be released and enabled in pairs.

The impact of various lock types on the CPU, screen, and keyboard:

Partial_wake_lock: to keep the CPU running, the screen and keyboard lights can be turned off.

Screen_dim_wake_lock: to keep the CPU running and display on the screen, but it can be dimmed to allow the keyboard light to turn off.

Screen_bright_wake_lock: allows you to keep the CPU running, highlight the screen, and turn off the keyboard light.

Full_wake_lock: keeps the CPU running, and keeps the screen and keyboard lights highlighted.

Acquire_causes_wakeup: the screen is highlighted immediately after the lock is obtained. It is typically used in notification so that users can view the lock immediately.

On_after_release: After the release lock (release (), the screen of the mobile phone will continue to shine for a while.

Package COM. example. sensortest; import android. OS. bundle; import android. OS. powermanager; import android. app. activity; import android. content. context; public class mainactivity2 extends activity {private powermanager. wakelock = NULL; @ overrideprotected void oncreate (bundle savedinstancestate) {setcontentview (R. layout. activity_main2); // todo auto-generated method stubsuper. oncreate (savedinstances Tate) ;}@ overridepublic void onresume () {acquirewakelock (this); super. onresume () ;}@ overridepublic void onpause () {releasewakelock (); super. onpause () ;}// obtain the lock public void acquirewakelock (context) {If (wakelock = NULL) {powermanager = (powermanager) (context. getsystemservice (context. power_service); wakelock = powermanager. newwakelock (powermanager. screen_dim_wake_lock, "my tag"); wake Lock. Acquire () ;}}// release the public void releasewakelock () {If (wakelock! = NULL & wakelock. isheld () {wakelock. Release (); wakelock = NULL ;}}}

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.