Reasons that the passed Intent would be NULL in onStartCommand

前端 未结 1 1316
离开以前
离开以前 2020-12-01 05:42

Is there any other reason that the Intent that is passed to onStartCommand(Intent, int, int) would be NULL besides the system restarting the service via a flag

1条回答
  •  一生所求
    2020-12-01 06:26

    I'm surprised there's no discussion of the incoming flags. I'm going to monitor 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: Flags were 0 so there was nothing actionable there. I've left the null check in there with no loss of function.

    Edit: Ok, I found it in the documentation of START_STICKY of all places! "if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must take care to check for this."

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

    0 讨论(0)
提交回复
热议问题