gpt4 book ai didi

android - 当调用 Activity/Fragment 改变方向时,Android 中的服务会停止吗?

转载 作者:太空狗 更新时间:2023-10-29 13:32:49 25 4
gpt4 key购买 nike

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

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 之前服务实际上不会停止吗?

最佳答案

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

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

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com