#226: Small fix to prevent message from being sent if IntentService is canceled

This commit is contained in:
Jessica Yuen 2014-03-03 23:04:55 -05:00
parent e4e3c555e9
commit af6713dc78

View File

@ -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) {