- First create Service .
- Run one thread in that service .
- In Run method use while loop.
Maintain one Boolean variable to stop and stat loop.
while(your boolean variable){ //your upload tax. }
I think this will help you.
Question
Suppose i run a web service in background(upload 100 images in binary format),If i want to stop then upload stop.If i want again start upload images then again start upload and also stop service (stop upload image into server) if i want. It is possible. If it is possible. Please explain how it is possible.
In this situation, i use AsyncTask Class but when call onPostExecute()
then not call onCancelled()
during executing onPostExecute()
. So How it is possible.
that means i talk about above, i sent request into server for upload 100 images. So when start upload images then images upload running but once i stop (stop upload image)service then stop upload image into server.
If i again start service then again start service.
Please help me anybody via example or tutorial or helpful resource links.
Solution
Maintain one Boolean variable to stop and stat loop.
while(your boolean variable){
//your upload tax.
}
I think this will help you.
OTHER TIPS
You need to clarify the question a bit, you want to stop the AsyncTask or the background service ?
What triggers the "stop" and where ?
In general I suggest you check if you were cancelled between each image upload but that won't stop the upload mid-file. This requires some more knowledge on how you are performing the upload.
Also, It sounds like you should consider a networking library like OkHTTP / Retrofit / Volley