不推荐使用Android FULL_WAKE_LOCK,但不推荐使用PARTIAL_WAKE_LOCK
作者:互联网
在这里我提到了唤醒屏幕的代码.我希望代码是监听仍然应用程序关闭和CPU清除,用户可以点击电源按钮,当我的屏幕解锁时,应用程序是同步像whatsapp.
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "whatever");
super.onCreate(savedInstanceState);
wl.acquire();
解决方法:
FULL_WAKE_LOCK已被弃用,最好使用PARTIAL_WAKE_LOCK.这是执行此操作的标准方法,
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
Wakelock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
欲了解更多实施方式,请访问官方链接,
https://developer.android.com/training/scheduling/wakelock.html
标签:android,android-wake-lock,wakelock 来源: https://codeday.me/bug/20190612/1222579.html