This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Android and the fly likes Multithreding issue in AsyncTask Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Multithreding issue in AsyncTask" Watch "Multithreding issue in AsyncTask" New topic

Multithreding issue in AsyncTask

Michal Horowic

Joined: Dec 26, 2011
Posts: 9
Hello everyone!

I am trying to implement solution for stopping execution of methods inside doInBackground method. As far as I know, doInBackground executes in other thread so I am wondering if this will work everytime I try it to run. Is it possible that downloading second and third data will execute, because change of shouldDo flag will not be seen by doInBackground thread?

Here is simple code, which I wrote especially for this example:

When I run above code, it works as I expected. Clicking on the back button after "downloading first data..." log goes to onPostExecute immediately after finished current downloading.

MichaƂ Horowic


I will be very greatful for the answer if this above code will work every time I try it to run, but I solved this in this way (better, because I don't have to wait for end of current downloading):

I agree. Here's the link:
subject: Multithreding issue in AsyncTask
Similar Threads
How to pass string from TCP server (a Runnable) to main activity (in Android)?
error while connecting to webservices
Android: Thread Exiting with uncaught exception while using httpUrlConnection (Android 4.0.3)
how to get progress bar after selecting a view
how to transfer images to ftp server in android