1

What is the best way to send a big file from an Android App to a distant server ?

Since there is one thread for the UI, I would like to keep 1 thread for the network connection (SFTP protocol) without reconnecting at every file I send. * AsyncTask is bad because the operation will last way too long and the UI will freeze. * IntentService is not the best since it has to reconnect for every file (when the Thread ends, it auto disconnects and I don't see how to keep the connection open).

Something nice would be : 1 thread for the UI, 1 thread to keep the connection open, 1 other thread for downloading/uploading to the server. Maybe with a standard Runnable class ?

Thanks in advance !

1 Answers1

0

Services are the right tool, especially as a service can run in the background to perform work even while the user is in a different application.

Baschi
  • 1,128
  • 11
  • 14
  • Considering to this thread: http://stackoverflow.com/questions/15524280/service-vs-intent-service, "Services should be too long". It runs in background but not on a different thread.Maybe keeping the connection on a Service and performing action with IntentService ? – Mathieu Mailhos Nov 27 '13 at 18:22
  • Ok, naming is naming. There are two types of service, started and bounded ones. What you are searching for is a started service. Once started, this service type can run in the background indefinitely, even if the component that started it is destroyed. So read **[Creating a Started Service](http://developer.android.com/guide/components/services.html#CreatingAService)** for understanding how to do this. There you will of course find a way to extend the `IntentService` class. – Baschi Nov 28 '13 at 07:09