I have this activity that starts and binds to a service:
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(context, SoundService.class);
context.startService(intent);
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
and I unbind by:
@Override
protected void onStop() {
context.unbindService(serviceConnection);
super.onStop();
}
The service keeps running even after closing the activity. Look at this scenario:
- Activity starts the service and binds to it
- Activity gets killed, the service keeps running,
onUnbind()
is called - Activity starts again, and binds to the running service
- Activity gets killed,
onUnbind()
is not called :(
Why is the onUnbind()
not being called?