Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a Service in Android stop when the calling Activity/Fragment changes orientation?

I am looking at the doc but it doesn't really explain this anywhere. I did find this:

The service will at this point continue running until Context.stopService() 
or stopSelf() is called.

What this tells me is the Service will continue running, but that is assuming when orientation change occurs that the Activity/Fragment does not automatically stop services it has started. I also found this:

Using startService() overrides the default service lifetime that is managed by
bindService(Intent, ServiceConnection, int): it requires the service to remain 
running until stopService(Intent) is called, regardless of whether any 
clients are connected to it.

Can I assume that the Service will actually not stop until I explicitly call stopService?

like image 277
Andy Avatar asked Dec 08 '25 06:12

Andy


1 Answers

for the title, answer is no.

A service doesn't stops when the calling activity/fragment changes orientation. It continues running unless or untill it is stopped explicitly

for the description, the answer is yes.

you definitely need to call either of the functions stopService() or stopSelf() to stop the service.

like image 165
Sahil Mahajan Mj Avatar answered Dec 10 '25 22:12

Sahil Mahajan Mj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!