上传大文件在后台(重新启动服务时,应用程序关闭) [英] Upload large file in background (service restarting when the app closed)

查看:146
本文介绍了上传大文件在后台(重新启动服务时,应用程序关闭)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传大文件(〜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后台服务用户退出应用后存活

<一个href=\"http://stackoverflow.com/questions/20804228/my-service-is-restarted-each-time-the-application-is-closed\">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从当前前台应用程序死亡,但在实践中,这不应该是一个关注的问题。)

  •   

这篇关于上传大文件在后台(重新启动服务时,应用程序关闭)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆