diff options
Diffstat (limited to 'core/java/android/app/IntentService.java')
-rw-r--r-- | core/java/android/app/IntentService.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/core/java/android/app/IntentService.java b/core/java/android/app/IntentService.java index 2b12a2a..804c8eb 100644 --- a/core/java/android/app/IntentService.java +++ b/core/java/android/app/IntentService.java @@ -18,6 +18,7 @@ public abstract class IntentService extends Service { private volatile Looper mServiceLooper; private volatile ServiceHandler mServiceHandler; private String mName; + private boolean mRedelivery; private final class ServiceHandler extends Handler { public ServiceHandler(Looper looper) { @@ -36,6 +37,19 @@ public abstract class IntentService extends Service { mName = name; } + /** + * Control redelivery of intents. If called with true, + * {@link #onStartCommand(Intent, int, int)} will return + * {@link Service#START_REDELIVER_INTENT} instead of + * {@link Service#START_NOT_STICKY}, so that if this service's process + * is called while it is executing the Intent in + * {@link #onHandleIntent(Intent)}, then when later restarted the same Intent + * will be re-delivered to it, to retry its execution. + */ + public void setIntentRedelivery(boolean enabled) { + mRedelivery = enabled; + } + @Override public void onCreate() { super.onCreate(); @@ -48,7 +62,6 @@ public abstract class IntentService extends Service { @Override public void onStart(Intent intent, int startId) { - super.onStart(intent, startId); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; @@ -56,6 +69,12 @@ public abstract class IntentService extends Service { } @Override + public int onStartCommand(Intent intent, int flags, int startId) { + onStart(intent, startId); + return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY; + } + + @Override public void onDestroy() { mServiceLooper.quit(); } |