PowerManager.WakeLock wakeLock = null;//获取电源锁,保持该服务在屏幕熄灭时仍然获取CPU时,保持运行private void acquireWakeLock(){if (null == wakeLock){PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE, "PostLocationService"); if (null != wakeLock){wakeLock.acquire(); }}}//释放设备电源锁private void releaseWakeLock(){if (null != wakeLock){wakeLock.release(); wakeLock = null; }}
700字范文,内容丰富有趣,生活中的好帮手!