diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 3904a91d8..302dbea0b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -203,10 +203,18 @@ public class KeychainIntentService extends IntentService implements ProgressDial Messenger mMessenger; + private boolean mIsCanceled; + public KeychainIntentService() { super("ApgService"); } + @Override + public void onDestroy() { + super.onDestroy(); + this.mIsCanceled = true; + } + /** * The IntentService calls this method from the default worker thread with the intent that * started the service. When this method returns, IntentService stops the service, as @@ -815,6 +823,10 @@ public class KeychainIntentService extends IntentService implements ProgressDial } private void sendErrorToHandler(Exception e) { + // Service was canceled. Do not send error to handler. + if (this.mIsCanceled) + return; + Log.e(Constants.TAG, "ApgService Exception: ", e); e.printStackTrace(); @@ -824,6 +836,10 @@ public class KeychainIntentService extends IntentService implements ProgressDial } private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle data) { + // Service was canceled. Do not send message to handler. + if (this.mIsCanceled) + return; + Message msg = Message.obtain(); msg.arg1 = arg1; if (arg2 != null) {