0

Possible Duplicate:
how to stop ASyncTask thread in android

Can I force all AsyncTasks in the stack to stop and let just UI thread run? I connect to network and download some info, images from server using AsyncTasks. But when the connection is lost, I need to stop them all. It is my application requirement.

Community
  • 1
  • 1
Bobans
  • 439
  • 6
  • 13
  • What is your problem.....and why are you intended to stop all async tasks..? – Pragnani Feb 04 '13 at 07:08
  • Leave `Asynctask` alone –  Feb 04 '13 at 07:14
  • Refer to these post's on how to stop a AsyncTask http://stackoverflow.com/questions/7821284/how-to-stop-asynctask-thread-in-android http://stackoverflow.com/questions/4429043/how-to-stop-asynctask-thread-in-android – Errol Dsilva Feb 04 '13 at 07:18

2 Answers2

0

This is how I have understood the proper use of AsyncTasks:

  • When you want to download use a Service and store it in a database.
  • Use AsyncTasks only when something is to be bound to the Activity/Fragment. Loading images to be displayed in the Activity/Fragment for instance.

I try to use Services as much as possible and have a callback to the Activity/Fragment that gets notified when my thing has been downloaded or similar.

Simon Zettervall
  • 1,764
  • 1
  • 15
  • 31
-1
you can simply cancel your Async tasks

    new task().cancel();
Sammar javed
  • 153
  • 1
  • 5