问题描述
我要上传大文件(〜10 - 100Mb的WiFi或移动网络),但在后台,因为用户可能会离开应用程序以后,系统将关闭该应用程序(如果不是enoguh内存)我创建了一个服务对于这种情况,但我的问题是,当我杀了应用程序服务重新启动,并上传重新开始。我发现同样的问题,而解决方法:
I would like to upload large files (~10 - 100Mb wifi or mobile network), but in background, because the user maybe will leave the app and later the system will close the app (if not enoguh memory) I created a service for this case but my problem is that when i killed the app the service restarting and the uploading start again. I found same problems without solution:
<一个href=\"http://stackoverflow.com/questions/17767767/keeping-background-service-alive-after-user-exit-app?rq=1\">keeping后台服务用户退出应用后存活
My服务是每个应用程序被关闭重新启动时间
所以它不会工作,但如何解决?如何YouTube应用???
So it won't work, but what is the solution? How does the youtube app???
推荐答案
您应该如果您担心的可能使用通过 startForeground()
方法的前台服务该服务被杀害。
You should use a foreground service via the startForeground()
method if you are concerned about the possibility of the service being killed.
从:
- 系统启动的服务可以使用startForeground(INT,通知)API把服务前台状态,在系统认为它是一些用户正在积极了解,因此不进行查杀时内存不足的候选人。 (它仍然是理论上可能的服务可以在极端存储器pressure从当前前台应用程序死亡,但在实践中,这不应该是一个关注的问题。)
这篇关于上传大文件在后台(重新启动服务时,应用程序关闭)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!