如何避免在关闭屏幕后应用程序停止工作--安卓
已解决
private void acquireWakeLock() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (wakeLock == null) {
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wakeLock");
if (!wakeLock.isHeld()) {
wakeLock.acquire();
SystemWorkTrace.reportTrace("*****system get wakeLock");
}else{
SystemWorkTrace.reportTrace("*****system already wakeLock");
}
}
}
private void releaseWakeLock() {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
SystemWorkTrace.reportTrace("*****system release WakeLock");
wakeLock = null;
}else{
SystemWorkTrace.reportTrace("*****system release WakeLock but wakeLock is null or not held");
}
}