gpt4 book ai didi

android - 在后台上传大文件(应用程序关闭时重新启动服务)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:38:51 24 4
gpt4 key购买 nike

我想上传大文件(~10 - 100Mb wifi 或移动网络),但在后台,因为用户可能会离开应用程序,稍后系统将关闭应用程序(如果没有足够的内存)我创建了一个这种情况下的服务,但我的问题是,当我终止应用程序时,服务重新启动并重新开始上传。我发现同样的问题没有解决方案:

keeping background service alive after user exit app

My service is restarted each time the application is closed

所以不行,那有什么办法呢? youtube 应用程序如何???

最佳答案

如果您担心服务被终止的可能性,您应该通过 startForeground() 方法使用前台服务。

来自Service Lifecycle Docs :

  • A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.)

关于android - 在后台上传大文件(应用程序关闭时重新启动服务),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20891698/

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