唤醒锁和 FLAG_KEEP_SCREEN_ON 之间的区别?
保持屏幕唤醒可以通过使用唤醒锁来完成
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
getClass().getName());
,或者通过将 FLAG_KEEP_SCREEN_ON 添加到窗口来完成,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
两者之间的技术差异是什么以及在推荐的性能和电池寿命方面是什么?
Keeping the screen awake can be accomplished by using a wakelock by
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
getClass().getName());
Or by adding the FLAG_KEEP_SCREEN_ON to the window,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
What is the technical difference between the two and in terms of performance and battery life which is recommended?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
唤醒锁为您提供了更多控制权(例如唤醒手机以在不关闭屏幕的情况下下载某些内容),并且要求您的应用程序持有唤醒锁权限。
因此,如果您只想在窗口可见时保持屏幕打开,则建议使用
FLAG_KEEP_SCREEN_ON
。A wakelock gives you way more control (Like waking the phone to download something without turning the screen off) and requires your application to hold the wakelock permission.
Therefore
FLAG_KEEP_SCREEN_ON
is recommended if all you want is to keep the screen on while your window is visible.Wakelock
是模糊的,因为它有许多不同的选项。标志FLAG_KEEP_SCREEN_ON
只能做到这一点。请参阅唤醒锁或PowerManager 了解 Android 的具体信息,以及具体实现的其他答案。
Wakelock
is vague, since it has many different options. The flagFLAG_KEEP_SCREEN_ON
only does that.Please see wakelock or PowerManager for Android specifics, and other answers for the exact implementation.
干杯!
Cheers!