[英]Android - Do I need a WakeLock?
I have a BroadcastReceiver that listen for the "SMS_SENT" Intent after an SMS has been sent. 我有一个BroadcastReceiver,在发送短信后监听“SMS_SENT”意图。 As far as I know, SMSManager does provide a wakelock so that it can actually send the SMS (I don't have any proof of this, but common sense would tell me that this is the case).
据我所知,SMSManager确实提供了一个唤醒锁,以便它可以实际发送短信(我没有任何证据证明这一点,但常识会告诉我这是事实)。
However, my BroadcastReceiver calls a WakefulIntentService, which uses its own wakelock, so that is ok. 但是,我的BroadcastReceiver调用一个WakefulIntentService,它使用自己的唤醒锁,所以没关系。 However, what about the receiver itself?
然而,接收器本身呢? Do I need to create a new wakelock so that I can guarantee that the WakefulIntentService is called?
我是否需要创建一个新的唤醒锁,以便我可以保证调用WakefulIntentService? Or can I just safely ignore this, just like one can do with a receiver for AlarmManager?
或者我可以安全地忽略这一点,就像可以使用AlarmManager的接收器一样?
Thanks 谢谢
However, what about the receiver itself?
然而,接收器本身呢? Do I need to create a new wakelock so that I can guarantee that the WakefulIntentService is called?
我是否需要创建一个新的唤醒锁,以便我可以保证调用WakefulIntentService?
Once your receiver calls WakefulIntentService.sendWakefulWork()
, the WakefulIntentService
engine acquires a WakeLock
. 一旦你的接收器调用
WakefulIntentService.sendWakefulWork()
, WakefulIntentService
引擎就会获得一个WakeLock
。
So long as you are not doing much work before that call, you should be fine. 只要你在那次通话之前没有做太多工作,你应该没事。
I think you do not need to create a wakelock for waiting the response. 我认为你不需要创建一个等待响应的唤醒锁。 Here are my thoughts.
这是我的想法。 First of all, imagine that your broadcast receiver for some reason does not receive the broadcast.
首先,想象一下您的广播接收器由于某种原因没有收到广播。 Then you will have an active wakelock.
然后你将有一个活跃的唤醒锁。 Secondly, it seems to me that the broadcast should activate your phone (because I've never seen sms application examples where a wakelock is created).
其次,在我看来,广播应该激活你的手机(因为我从未见过短信应用程序示例,其中创建了一个唤醒锁)。 So to my point of view you do not need to create a wakelock.
因此,就我而言,您不需要创建唤醒锁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.