当调用Activity / Fragment更改方向时,Android中的服务是否会停止?

时间:2012-12-04 04:35:20

标签: android android-service

我正在查看文档,但它并没有真正解释这个问题。我确实找到了这个:

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

这告诉我服务将继续运行,但是假设当方向发生变化时,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之前,我能否假设服务实际上不会停止?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

标题,答案是否。

当呼叫活动/片段改变方向时,服务不会停止。它继续运行,除非或直到它被明确停止

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

您肯定需要调用stopService()stopSelf()函数来停止服务。