android 休眠

//保持不休眠
private void acquireWakeLock() {
    if(mWakeLock == null) {
        PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                this.getClass().getCanonicalName());
        mWakeLock.acquire();
    }

}
//休眠
private void releaseWakeLock() {
    if(mWakeLock != null) {
        mWakeLock.release();
        mWakeLock = null;
    }
}

你可能感兴趣的:(Android)