How to make the phone screen not standby in Android

Source: Internet
Author: User
Tags network function

On Android, applying for Wakelock can keep your process going even if your phone goes into sleep mode, it's useful to have a network function in the background, which can keep the operation going.

Method: Join before the operation

PowerManager pm = (powermanager) mcontext.getsystemservice (Context.power_service);
WakeLock = Pm.newwakelock (Powermanager.partial_wake_lock, Constants.tag);
Wakelock.acquire ();
Where Newwakelock has two parameters, the first parameter defines the behavior, the second parameter is the debug tag, which can be defined as the class name. The first parameter takes the following values:

flag Value CPU screen keyboard
partial_wake_lock on* off off
screen_dim_wake_lock on dim off
screen_bright_wake_lock on bright off
full_wake_lock on bright bright


Don't forget to release it after the operation is complete.

if (wakeLock! = null) {
Wakelock.release ();
WakeLock = null;
}
Also, to add permission: <uses-permission android:name= "Android.permission.WAKE_LOCK"/>

--------------------------------------------------------------------------------------------------------------- -------------

Another way is to

    1. @Override   
    2. protected void onCreate (Bundle icicle) {
    3. Super . onCreate (Icicle);

    4. After testing this is still relatively useful, multimedia playback settings are not standby.
    5. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    6.     }  

This parameter also keeps the screen active and does not go into hibernation, saving some more than the previous security.

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.