[英]Is wakelock needed in broadcast receiver for ACTION_SCREEN_OFF
I'm registering a broadcast receiver that will be activated when the screen is turned off. 我正在注册一个广播接收器,它将在屏幕关闭时被激活。 The receiver performs a short, synchronous operation in OnReceive.
接收器在OnReceive中执行简短的同步操作。 This operation must happen in my app before the device sleeps.
设备休眠之前,此操作必须在我的应用程序中进行。
My question: do I need to acquire a wakelock here, or is it guaranteed that Android will let my receiver finish the OnReceive method? 我的问题:我是否需要在此处获取唤醒锁,还是可以保证Android将让我的接收器完成OnReceive方法? My code takes a few milliseconds to run, but let's say it takes 1 second for the sake of discussion.
我的代码需要花费几毫秒的时间才能运行,但是为了讨论起见,它需要1秒钟。
I'm using this code to register the receiver: 我正在使用以下代码注册接收者:
BroadcastReceiver receiver = new MyReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(receiver, filter);
I couldn't find an answer in the documentation or by searching, so I would appreciate any help, thank you! 我无法在文档中或通过搜索找到答案,因此,我们将不胜感激,谢谢!
Yes device might sleep. 是的,设备可能会休眠。 Newaz why are you taking a chance?
Newaz您为什么要冒险? Better aquire a Partial wakelock and release it at the end of onReceive.
最好获取一个部分唤醒锁,然后在onReceive结束时释放它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.