Refactor unbindService()

This commit is contained in:
Adeel Zafar 2019-08-19 01:18:40 +05:00
parent f5672a4799
commit 106d085570

View File

@ -94,7 +94,6 @@ public class ZimHostActivity extends BaseActivity implements
BookOnDiskDelegate.BookDelegate bookDelegate;
HotspotService hotspotService;
private String ip;
boolean bound;
private ServiceConnection serviceConnection;
ArrayList<String> selectedBooksPath = new ArrayList<>();
@ -133,13 +132,11 @@ public class ZimHostActivity extends BaseActivity implements
public void onServiceConnected(ComponentName className, IBinder service) {
HotspotService.HotspotBinder binder = (HotspotService.HotspotBinder) service;
hotspotService = binder.getService();
bound = true;
hotspotService.registerCallBack(ZimHostActivity.this);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
bound = false;
}
};
@ -215,14 +212,11 @@ public class ZimHostActivity extends BaseActivity implements
private void bindService() {
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
bound = true;
}
private void unbindService() {
if (bound && !isServerStarted) {
hotspotService.registerCallBack(null); // unregister
if (hotspotService != null) {
unbindService(serviceConnection);
bound = false;
}
}