简体   繁体   English

Android - 我需要WakeLock吗?

[英]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.

相关问题 Android - 使用LocationManager.requestLocationUpdates时,是否需要WakeLock? - Android - When using LocationManager.requestLocationUpdates, do I need a WakeLock? Android:完成一个非常短的任务是否需要WakeLock? - Android: Do I need a WakeLock for a really short task? 如果我不创建线程,是否需要获取 WakeLock? - Do I need to obtain a WakeLock if I don't create threads? 我是否需要使用AlarmManager和WakeLock定期使用LocationClient? - Do I need to Use an AlarmManager and WakeLock to periodically use a LocationClient? 如果将服务放在奥利奥的前台,是否需要设置唤醒锁? - Do I need to set a wakelock if a service is put in the foreground in oreo? 试着了解我是否需要WakeLock - Trying to understand if I need WakeLock 您需要WakeLock来进行CPU密集型服务吗? - Do you need a WakeLock for CPU intensive services? 不使用广播接收器处理从Alarm Manager发送的IntentServices时,是否需要获取唤醒锁? - Do I need to acquire a wakelock when not using a broadcast receiver to handle IntentServices sent from Alarm Manager? Android WakeLock - Android WakeLock 如果获得唤醒锁并且我的应用程序崩溃了,我该怎么办? - If a wakelock is acquired and my app crashes, what should I do?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM