Reasons that the accepted intention will be NULL in onStartCommand

Is there any other reason that the Intent passed to onStartCommand(Intent, int, int) should be NULL, except for restarting the system via a flag, for example START_STICKY ?

In addition, when the service is restarted by the system, the Intent.getAction() method returns NULL ... sometimes. Intent is not NULL only getAction()

I asked here , but have not received an answer yet.

UPDATE . After talking with Mark Murphy, he suggested that I return START_REDELIVER_INTENT in the onStartCommand() in my service instead of START_STICKY , so that all intent is sent after the restart,

I did not do this initially because I was worried that if the service is trying to do something, then in the middle of something restarted, will it be recognized that it started to do something? I think this is logic, I will have to answer for :)

+75
android android-intent android-service
Dec 07 '11 at 19:38
source share
1 answer

I am surprised that there is no discussion of incoming flags. I am going to track this in the logs with the following:

 if (null == intent || null == intent.getAction ()) { String source = null == intent ? "intent" : "action"; Log.e (TAG, source + " was null, flags=" + flags + " bits=" + Integer.toBinaryString (flags)); return START_STICKY; } 

Update: the flags were 0, so nothing worked there. I left a null check there without losing function.

Edit: Well, I found it in the START_STICKY documentation from all places! "if pending start commands are not sent to the service, they will be called with an object of zero intent, so you must take care of this."

http://developer.android.com/reference/android/app/Service.html

+35
Dec 19 '13 at 16:27
source share



All Articles