OnUnbind is not called when binding activity to a running service

I have this activity, which starts and binds to the 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 disconnect:

@Override
protected void onStop() {
    context.unbindService(serviceConnection);

    super.onStop();
}

The service continues to work even after the operation is closed. Take a look at this scenario:

  • The action starts the service and contacts it
  • Activity is killed, the service continues to work, onUnbind()called
  • The action starts again and binds to the running service.
  • Activity is killed, onUnbind()called not : (

Why onUnbind()not called?

+4
source share
2 answers

return true from onUnbind, , bindService , onRebind, onUnbind

+3

? .

​​ , unbindService() IF, , , , bind AUTO_CREATE. startService(), ​​ , stopSelf() ,

0

Source: https://habr.com/ru/post/1627851/


All Articles