From 5d9bf309c93e96c76ac532767d3b751ad99415e4 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 3 Nov 2011 22:10:24 +0100 Subject: [PATCH] Avoid NullPointerException in services when process/service is restarted See issue 3750 --- src/com/fsck/k9/service/CoreService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/service/CoreService.java b/src/com/fsck/k9/service/CoreService.java index dcd892924..bb7acee57 100644 --- a/src/com/fsck/k9/service/CoreService.java +++ b/src/com/fsck/k9/service/CoreService.java @@ -202,12 +202,26 @@ public abstract class CoreService extends Service { public final void onStart(Intent intent, int startId) { // deprecated method but still used for backwards compatibility with Android version <2.0 + /* + * When a process is killed due to low memory, it's later restarted and services that were + * started with START_STICKY are started with the intent being null. + * + * For now we just ignore these restart events. This should be fine because all necessary + * services are started from K9.onCreate() when the Application object is initialized. + * + * See issue 3750 + */ + if (intent == null) { + stopSelf(startId); + return; + } + // Acquire new wake lock TracingWakeLock wakeLock = acquireWakeLock(this, "CoreService onStart", K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT); if (K9.DEBUG) { - Log.i(K9.LOG_TAG, "CoreService: " + className + ".onStart(" + intent + ", " + startId); + Log.i(K9.LOG_TAG, "CoreService: " + className + ".onStart(" + intent + ", " + startId + ")"); } // If we were started by BootReceiver, release the wake lock acquired there.