1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 05:02:26 -05:00

Avoid NullPointerException in services when process/service is restarted

See issue 3750
This commit is contained in:
cketti 2011-11-03 22:10:24 +01:00
parent 57e0abbf8f
commit 5d9bf309c9

View File

@ -202,12 +202,26 @@ public abstract class CoreService extends Service {
public final void onStart(Intent intent, int startId) { public final void onStart(Intent intent, int startId) {
// deprecated method but still used for backwards compatibility with Android version <2.0 // 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 // Acquire new wake lock
TracingWakeLock wakeLock = acquireWakeLock(this, "CoreService onStart", TracingWakeLock wakeLock = acquireWakeLock(this, "CoreService onStart",
K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT); K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT);
if (K9.DEBUG) { 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. // If we were started by BootReceiver, release the wake lock acquired there.