Upload large file in background (service restarting when the app closed)

微笑、不失礼 提交于 2019-12-05 08:12:11

You should use a foreground service via the startForeground() method if you are concerned about the possibility of the service being killed.

From the 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.)
Matt

Do you have control over the server? This seems just like:

Uploading big files over HTTP

Googling brought up a proposal for the Gears project:

https://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal

If you can use a server/plugin/module that will allow for Ranged PUTs, that's your best bet, otherwise you may have to roll-your-own "chunking"... Depending on your tools and knowledge, that may be the best option anyway, you could tweak it to optimize it for your specific mobile conditions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!