Android:禁用或至少忽略待机
我正在编写一个具有闹钟功能的应用程序,即在设备进入待机状态时它必须继续运行。显然,情况并非如此。我怎样才能做到这一点?
如果我可以完全阻止设备进入待机状态,那就更好了 - 我可以这样做吗?
I'm writing an app with alarm functionality, i.e. it will have to continue running while the device goes into standby. Apparently, this is not the case. How can I achieve that?
It would be even better if I could prevent the device from going into standby at all - can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 应用程序可以通过唤醒锁阻止设备进入待机状态,但这只能在短时间内用于需要用户查看屏幕而不触摸屏幕的特定任务。
对于任何其他长时间目的,您必须使用系统 AlarmManager< /a> 安排应用程序的未来操作。
使用永久唤醒锁会使您的应用程序消耗电池电量。
Android applications can prevent the device from going into standby with a wake lock but this should be used only for short periods of time for specific tasks which require the user to look at the screen without touching it.
For any other long time purposes, you have to use the system AlarmManager to schedule future actions of your application.
Using a permanent wake lock would make your app a battery drainer.
服务始终运行,即使在待机状态下也是如此,因此您应该使用它。
可以通过唤醒锁来防止待机。请注意,只有少数应用程序会阻止待机(例如游戏、视频播放器......)。
A service runs always, even in standby, so you should use it.
Preventing standby can be done with a wake lock. Be careful, there are only a few apps that should prevent standby (like games, video players...).