From 9418ed2b1e3f8f136ffefa2fe9f560fe418dcf68 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Fri, 21 Jun 2019 21:07:29 -0500 Subject: [PATCH] Fixing problems with the NetworkServiceManager - Removed the 'mStartingService' boolean flag from the NetworkServiceManager. - Introducing the 'passInfo' flag, used to decide whether or not to pass the connection info to the NetworkService calling the 'bootstrapService' method. --- .../api/android/NetworkServiceManager.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java index 491857d..f3b65be 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java @@ -55,7 +55,7 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb private boolean mAutoConnect; private boolean mVerifyLatency; // Flag used to make sure we only call 'bindService' once. - private boolean mStartingService; +// private boolean mStartingService; /** * Runnable used to schedule a service disconnection once the app is not visible to the user for @@ -86,9 +86,7 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb @Override public void onActivityResumed(Activity activity) { mHandler.removeCallbacks(mDisconnectRunnable); - if(mService == null && !mStartingService){ - // Setting this flag to 'true' to avoid repeated calls to the bindService. - mStartingService = true; + if(mService == null){ // Creating a new Intent that will be used to start the NetworkService Context context = mContextReference.get(); Intent intent = new Intent(context, NetworkService.class); @@ -145,15 +143,19 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb IBinder service) { // We've bound to LocalService, cast the IBinder and get LocalService instance NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service; - mService = binder.getService(); - // Setting the 'starting service' flag back to false - mStartingService = false; - passRequiredInfoToConfigureService(); + boolean passInfo = false; + if(mService == null){ + mService = binder.getService(); + // We only pass the required information in case this is the first time we get a reference + // to the NetworkService instance. + passInfo = true; + } + if(passInfo) + passRequiredInfoToConfigureService(); } @Override public void onServiceDisconnected(ComponentName componentName) { - mStartingService = false; } };