Android 唤醒锁问题?
海,我使用广播接收器开发了一个应用程序。我需要始终唤醒我的应用程序。所以我使用了唤醒锁。这里是我的代码
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
问题
1.如果我总是醒来,我的电池就会耗尽。
2.如果我调用w1.acquier()
,是否需要释放w1(即w1.release)
Hai i developed a application using broadcast receiver.I need to wake my Application always.so i used wakelock.here my code
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
problem
1.If i wake up always my battery is getting drained.
2.if i cal w1.acquier()
,Is necessary to release the w1(ie w1.release)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白你的第一个问题是什么。我认为如果你想继续唤醒你的应用程序,这是事实吗?
如果您想要实现保持屏幕不变暗,您可以尝试以下代码:
I don't understand what is your 1st question.. I thought that is a fact if you want to keep waking up your application?
If keep your screen not dimming down is what you want to achieve, you could try this code:
即使屏幕关闭,唤醒锁也会使 CPU 在您的应用程序上运行,因此会严重耗尽电池电量。当您不再需要应用程序在后台继续运行时(例如不再等待任何回调),您希望对唤醒锁调用释放。
Wake lock keeps the cpu running on your application even when the screen is off so it will drain your battery hard. You want to call release on your wake lock when you no longer need the application to keep running in the background (example not waiting for any more callbacks).