Moved the service binding to the onActivityResumed callback

This commit is contained in:
Nelson R. Perez 2018-10-02 12:36:36 -05:00
parent 25b7e6c8c6
commit 857236a1ea

View file

@ -78,7 +78,10 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
public void onActivityCreated(Activity activity, Bundle bundle) { } public void onActivityCreated(Activity activity, Bundle bundle) { }
@Override @Override
public void onActivityStarted(Activity activity) { public void onActivityStarted(Activity activity) { }
@Override
public void onActivityResumed(Activity activity) {
mHandler.removeCallbacks(mDisconnectRunnable); mHandler.removeCallbacks(mDisconnectRunnable);
if(mService == null){ if(mService == null){
// Creating a new Intent that will be used to start the NetworkService // Creating a new Intent that will be used to start the NetworkService
@ -101,14 +104,10 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
.putExtra(NetworkService.KEY_CUSTOM_NODE_URLS, customNodes) .putExtra(NetworkService.KEY_CUSTOM_NODE_URLS, customNodes)
.putExtra(NetworkService.KEY_AUTO_CONNECT, mAutoConnect) .putExtra(NetworkService.KEY_AUTO_CONNECT, mAutoConnect)
.putExtra(NetworkService.KEY_ENABLE_LATENCY_VERIFIER, mVerifyLatency); .putExtra(NetworkService.KEY_ENABLE_LATENCY_VERIFIER, mVerifyLatency);
context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
} }
} }
@Override
public void onActivityResumed(Activity activity) {}
@Override @Override
public void onActivityPaused(Activity activity) { public void onActivityPaused(Activity activity) {
mHandler.postDelayed(mDisconnectRunnable, DISCONNECT_DELAY); mHandler.postDelayed(mDisconnectRunnable, DISCONNECT_DELAY);