gpt4 book ai didi

android - GCM-App 真的需要唤醒锁吗?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:45:45 26 4
gpt4 key购买 nike

我不太确定如何解释 GCM Client documentation 中的这句话:

The android.permission.WAKE_LOCK permission so the application can keep the processor from sleeping when a message is received. Optional—use only if the app wants to keep the device from sleeping.

.

If you don't hold a wake lock while transitioning the work to a service, you are effectively allowing the device to go back to sleep before the work completes. The net result is that the app might not finish processing the GCM message until some arbitrary point in the future, which is not what you want.

Using WakefulBroadcastReceiver is not a requirement. If you have a relatively simple app that doesn't require a service, you can intercept the GCM message in a regular BroadcastReceiver and do your processing there.

我不太确定我的应用是否需要保持唤醒锁(或者它是否需要服务)。推送通知部分对应用程序非常重要,不应延迟超过几分钟。 BroadcastReceiver 是否有可能在接收到所有数据之前被挂起?

最佳答案

Is there a chance that the BroadcastReceiver gets suspended before receiving all the data?

没有。在整个 4K 或更小的有效载荷下载完毕并可供您使用之前,您将无法获得控制权。

但是,onReceive() 是在主应用程序线程上调用的,因此如果您的工作需要超过一毫秒左右,您应该使用 WakefulBroadcastReceiver 和一个IntentService 用于该工作。或者,如果您愿意,可以使用 my WakefulIntentService和一个常规的 BroadcastReceiver

关于android - GCM-App 真的需要唤醒锁吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22543582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com