2

I have an Android App that needs to upload, download data files between 10-12MB relatively often. Given that my app is more popular in countries like India which may not have good internet connectivity I am working under following constraints

  • User may not be connected to internet 24x7
  • User's interaction does not depend on whether the download/upload succeeds.

This is a poems app where we download new poems to users phone and upload user's poems to our server whenever we are connected to internet.

I understand that using "com.loopj.android.http.AsyncHttpClient;" for the communication but I was wondering if there are any better alternatives which can do the following:

  • Should I start a service which provides interfaces for upload/download ?
  • Is it possible to do this stuff in background, even when user is not using the app?
  • 10-12 MB relatively often? Are you telling me that you want each user to re-download the entire database of poems every time that database is updated? Shouldn't you just have the user download the updates to the data (instead of the entire database each time)? – Stephan Branczyk Jun 13 '14 at 21:31
  • And why would you have the same requirements for uploading as well? Will each user really upload thousands of poems at once? I doubt it. And even if some do, those may prefer to use an actual PC when they have to do large batch of uploads. – Stephan Branczyk Jun 13 '14 at 21:35
  • 1
    Guys lets not get into why it is 10-12 MB or whether it is good thing or not. Let us stick to the question asked. – Eastern Monk Jun 14 '14 at 10:09

1 Answers1

2

Yes, you should use a service, in particular a foreground service (to show a notification as the upload progresses). Additionally, a foreground service is not likely to be killed by Android:

... the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory.

For downloads, Android provides a ready-made solution called DownloadManager. It already includes the capability to resume downloads in case the connection is lost.

For uploads, there is no equivalent (at least as far as I know). You would have to roll out your own solution, probably involving the Content-Range HTTP header. It depends a lot on your server, for example Google Drive has an API for this. Also take a look at Resume file upload/download after lost connection (Socket programming) (although it's with sockets, the concepts are more or less the same).

Another options is to use a SyncAdapter for this task. See Transferring Data using Sync Adapters. I'm not sure if this supports resuming though.

Community
  • 1
  • 1
matiash
  • 54,791
  • 16
  • 125
  • 154