我正在查看文档,但它并没有在任何地方真正解释这一点。我确实找到了这个:

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

这告诉我的是 Service 将继续运行,但这是假设当发生方向更改时,Activity/Fragment 不会自动停止它已启动的服务。我也发现了这个:
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.

我可以假设在我明确调用 stopService 之前服务实际上不会停止吗?

最佳答案

对于标题,答案是否定的。

当调用 Activity/fragment 改变方向时,服务不会停止。除非或直到明确停止,否则它会继续运行

对于描述,答案是肯定的。

您肯定需要调用 stopService()stopSelf() 函数中的任何一个来停止服务。

关于android - 当调用 Activity/Fragment 改变方向时,Android 中的服务是否停止?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13696152/

10-12 00:24
查看更多