--powermanager of system services provided by Android (Power service)

Source: Internet
Author: User

--powermanager of system services provided by Android (Power service)

--Reprint Please specify source: Coder-pig



Introduction to this section:

This section focuses on Android for the system services we provide: An API for PowerManager power management,

Used to manage CPU running, keyboard or screen lit up; but unless it's a necessity, otherwise, you should try to avoid

Use this class, and be sure to release it when you're done with it! This section is not too deep to explain, because this design to the bottom of the

Some things, in the future need to use further research, and then write another blog summary! So this section describes the main

Some basic concepts, powermanager,wakelock lock mechanism and so on!




The knowledge point diagram of this section:




code Example:

A tool class for managing Wakelock and power management for Android devices:

Import Android.content.context;import Android.content.sharedpreferences;import Android.os.powermanager;import Android.preference.preferencemanager;public class Managewakelock {private static Powermanager.wakelock MWakeLock = nul    L    private static Powermanager.wakelock Mpartialwakelock = null;    Private static Final Boolean Prefs_screenon_default = true;    Private static Final Boolean prefs_dimscreen_default = false;    private static final String Prefs_timeout_default = "30";        public static synchronized void Acquirefull (Context mcontext) {if (Mwakelock! = null) {return;        } PowerManager mPm = (powermanager) mcontext.getsystemservice (Context.power_service);        Sharedpreferences mprefs = preferencemanager.getdefaultsharedpreferences (Mcontext);        int flags; Flags = Powermanager.screen_bright_wake_lock |        Powermanager.acquire_causes_wakeup;        Mwakelock = Mpm.newwakelock (Flags, "Managerwakelock"); Mwakelock.setreferencecoUnted (FALSE);    Mwakelock.acquire ();        } public static synchronized void acquirepartical (Context mcontext) {//check If partial lock already exists        if (mpartialwakelock! = null) {return;        } PowerManager mPm = (powermanager) mcontext.getsystemservice (Context.power_service); Mpartialwakelock = Mpm.newwakelock (Powermanager.screen_bright_wake_lock |        Powermanager.acquire_causes_wakeup, "Managerwakelock");            Mpartialwakelock.setreferencecounted (FALSE);        Mpartialwakelock.acquire ();            }} public static synchronized void Releasefull () {if (Mwakelock! = null) {mwakelock.release ();        Mwakelock = null; }} public static synchronized void Releasepartial () {if (Mpartialwakelock! = null) {Mpartialwa             Kelock.release ();        Mpartialwakelock = null; }} public static synchronized void Releaseall () {ReleasEfull ();    Releasepartial (); }}



Resources:

Http://www.open-open.com/lib/view/open1343207436974.html

http://blog.csdn.net/xieqibao/article/details/6562256

Http://blog.chinaunix.net/uid-27411029-id-4040727.html







--powermanager of system services provided by Android (Power service)

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.