我在 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/