gpt4 book ai didi

Android IntentService 以空 Intent 触发

转载 作者:太空宇宙 更新时间:2023-11-03 13:14:51 24 4
gpt4 key购买 nike

我在 Crashlytics 中看到崩溃:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference at com.myapp.APKOfferQueueManagerIntentService.onHandleIntent(SourceFile:71) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61)

IntentService 怎么会被 null intent 触发?

最佳答案

IntentService 可以像所有其他服务一样停止,但它将由“系统”重新启动,直到 onHandleIntent() 完成其工作。在这种情况下,documentation intent 参数

... may be null if the service is being restarted after its process has gone away

要始终将原始 Intent 作为参数,请使用

setIntentRedelivery(true);

IntentService 的构造函数中。

还要注意

If multiple Intents have been sent, only the most recent one is guaranteed to be redelivered.

关于Android IntentService 以空 Intent 触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37960917/

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