How to upload data into sever and download data from sever via background service in android? [closed]

StackOverflow https://stackoverflow.com/questions/23670073

  •  23-07-2023
  •  | 
  •  

Question

I am new on android platform. I want upload data(image) and download data(image) via background service and also if i want cancel upload or download then easily it is possible. Please help me. How it is do. I have no idea about this.

I want help by giving sample example or tutorial links or useful/helpful resource links.

Was it helpful?

Solution

Uploading/downloading data(images) from the server are time consuming tasks. So its always better to run the time consuming tasks in background thread besides on main UI thread. So that it does not block the user interface.

You should go for the AsynchTask which will help you to implement the downloading data from the server in its three methods effectively which are :

doInBackground() -invoked on the background thread immediately after onPreExecute() finishes executing.

onPreExecute() - which is invoked on the UI thread before the task is executed.

onPostExecute()- invoked on the UI thread after the background computation finishes.

Check out the below Uploading Image on Server and Image Uploading

For Downloading image check below links

Downloading image from Url

Download image from Server

Hope this will guide you.

OTHER TIPS

you can use asynctask , check out the docs, http://developer.android.com/reference/android/os/AsyncTask.html

you can launch asynctask from service and put the downloading code in doInBackground and if you need to updaste the user regarding the progress use onPostExecute (which is runs on the main thread)

also this is an helpful tutorial (there are many more)

http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html

hope this will help get you started

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top