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.
This commit is contained in:
parent
d605a47e0e
commit
9418ed2b1e
1 changed files with 11 additions and 9 deletions
|
@ -55,7 +55,7 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
|
||||||
private boolean mAutoConnect;
|
private boolean mAutoConnect;
|
||||||
private boolean mVerifyLatency;
|
private boolean mVerifyLatency;
|
||||||
// Flag used to make sure we only call 'bindService' once.
|
// 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
|
* 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
|
@Override
|
||||||
public void onActivityResumed(Activity activity) {
|
public void onActivityResumed(Activity activity) {
|
||||||
mHandler.removeCallbacks(mDisconnectRunnable);
|
mHandler.removeCallbacks(mDisconnectRunnable);
|
||||||
if(mService == null && !mStartingService){
|
if(mService == null){
|
||||||
// Setting this flag to 'true' to avoid repeated calls to the bindService.
|
|
||||||
mStartingService = true;
|
|
||||||
// Creating a new Intent that will be used to start the NetworkService
|
// Creating a new Intent that will be used to start the NetworkService
|
||||||
Context context = mContextReference.get();
|
Context context = mContextReference.get();
|
||||||
Intent intent = new Intent(context, NetworkService.class);
|
Intent intent = new Intent(context, NetworkService.class);
|
||||||
|
@ -145,15 +143,19 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
|
||||||
IBinder service) {
|
IBinder service) {
|
||||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
||||||
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
|
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
|
||||||
|
boolean passInfo = false;
|
||||||
|
if(mService == null){
|
||||||
mService = binder.getService();
|
mService = binder.getService();
|
||||||
// Setting the 'starting service' flag back to false
|
// We only pass the required information in case this is the first time we get a reference
|
||||||
mStartingService = false;
|
// to the NetworkService instance.
|
||||||
|
passInfo = true;
|
||||||
|
}
|
||||||
|
if(passInfo)
|
||||||
passRequiredInfoToConfigureService();
|
passRequiredInfoToConfigureService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName componentName) {
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
mStartingService = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue