Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce8d4f51 authored by Ryan Lothian's avatar Ryan Lothian
Browse files

Improve documentation for IntentService

The argument to onHandleIntent(Intent) is sometimes null. This
is surprising, and isn't mentioned in the Javadoc.

+ Add a warning about this behavior to the method's Javadoc.

+ Add @Nullable annotation so tools that do null safety analysis
  (e.g. Android Studio) will generate a warning for apps that
  dereference the intent parameter without checking.

Change-Id: I26485eba8c79ba700dd9423e5d356efbb423becd
parent c1b92381
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app;
package android.app;


import android.annotation.WorkerThread;
import android.annotation.WorkerThread;
import android.annotation.Nullable;
import android.content.Intent;
import android.content.Intent;
import android.os.Handler;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.HandlerThread;
@@ -113,7 +114,7 @@ public abstract class IntentService extends Service {
    }
    }


    @Override
    @Override
    public void onStart(Intent intent, int startId) {
    public void onStart(@Nullable Intent intent, int startId) {
        Message msg = mServiceHandler.obtainMessage();
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.arg1 = startId;
        msg.obj = intent;
        msg.obj = intent;
@@ -127,7 +128,7 @@ public abstract class IntentService extends Service {
     * @see android.app.Service#onStartCommand
     * @see android.app.Service#onStartCommand
     */
     */
    @Override
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
        onStart(intent, startId);
        onStart(intent, startId);
        return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
        return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
    }
    }
@@ -143,6 +144,7 @@ public abstract class IntentService extends Service {
     * @see android.app.Service#onBind
     * @see android.app.Service#onBind
     */
     */
    @Override
    @Override
    @Nullable
    public IBinder onBind(Intent intent) {
    public IBinder onBind(Intent intent) {
        return null;
        return null;
    }
    }
@@ -158,7 +160,11 @@ public abstract class IntentService extends Service {
     *
     *
     * @param intent The value passed to {@link
     * @param intent The value passed to {@link
     *               android.content.Context#startService(Intent)}.
     *               android.content.Context#startService(Intent)}.
     *               This may be null if the service is being restarted after
     *               its process has gone away; see
     *               {@link android.app.Service#onStartCommand}
     *               for details.
     */
     */
    @WorkerThread
    @WorkerThread
    protected abstract void onHandleIntent(Intent intent);
    protected abstract void onHandleIntent(@Nullable Intent intent);
}
}