Make unbinding from CodeGeneratorService cleaner
Fix by creating an unbind call that unbinds from the service
and clears state so we don't end up in a situation that can try to
unbind twice.
@@ -51,7 +51,7 @@ public class CodeGeneratorManager {
public void onServiceConnected(ComponentName className, IBinder binder) {
try {
if (!mResumed) {
- mContext.unbindService(mCodeGenerationConnection);
+ unbind();
} else {
mGeneratorService = ((CodeGeneratorService.CodeGeneratorBinder) binder).getService();
@@ -76,9 +76,7 @@ public class CodeGeneratorManager {
*/
public void onPause() {
mResumed = false;
- if (isBound()) {
- mContext.unbindService(mCodeGenerationConnection);
- }
+ unbind();
}
/**
@@ -90,6 +88,16 @@ public class CodeGeneratorManager {
mStoredRequests.clear();
}
+ /**
+ * Checks if the service is currently bound and unbinds it if it is.
+ */
+ protected void unbind() {
+ if (isBound()) {
+ mContext.unbindService(mCodeGenerationConnection);
+ mGeneratorService = null;
+ }
+ }
+
/**
* Calls the Service to request code generation for the workspace passed in.
*
