Cómo detener el servicio después de iniciarlo
Antes de discutir cómo detener el servicio, debemos revisar las dos formas de iniciar el servicio.
Ciclo de vida: onCreate()-gt; onStartCommand()-gt; Servicio en ejecución-gt; onDestroy()
Ciclo de vida: onCreate()-gt; gt; los clientes están vinculados a service-gt; onUnbind()-gt; onDestroy()
(1)startServic: call onCreate()-gt; )stopService: llamar a onDestory()
(1)bindservice: llamar a onCreate()-gt; onBind()
(2)unbindService: llamar a onUnbind()-gt; )
(1)startServic: llamar a onCreate()-gt; onStartCommand()
(2)bindService: llamar a onBind()
(3)stopService : ¡El servicio todavía se está ejecutando sin llamar a onDestory()!
(4) unbindService: llame a onUnbind()-gt; onDestory() ¡El servicio está cerrado en este momento!
(1)startServic: llamar a onCreate()-gt; onStartCommand()
(2)bindService: llamar a onBind()
(3)unbindService: ¡La llamada al servicio onUnbind() todavía se está ejecutando!
(4)stopService: ¡Llame a onDestory() y el Servicio se cerrará en este momento!