简体   繁体   中英

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 ?

是的。您必须使用stopService()方法停止它,或者您可以使用stopSelf()在不再需要服务时停止。它将自动停止服务。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM