gpt4 book ai didi

Android:在后台运行一个线程

转载 作者:太空狗 更新时间:2023-10-29 15:34:08 24 4
gpt4 key购买 nike

当我在 android 中关闭应用程序时,有什么方法可以在后台保留一个线程吗?我阅读了一项服务,但实现它比我需要的太多了。谢谢

最佳答案

Hi, is there any way to leave a thread in background when i close the app in android?

默认情况下会发生这种情况。这并不意味着这是个好主意。

I read about a Service but implementing it is too much than i need.

更有可能的是,这正是您所需要的。

如果您在 Activity 中启动一个线程,然后未能停止该线程,它将永远运行,直到 Android 终止该进程,因为您无法停止它。唯一可接受的异常是,如果您的线程自行停止,那么您必须非常非常小心,以确保它确实完全终止。另一方面,您可以随时从任何 Activity 安排停止正在运行的 Service,并且 Service 可以安排停止线程,因此您不会无限期地泄漏线程。

我强烈建议您实现管理线程的服务。

关于Android:在后台运行一个线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2277371/

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