0

I am currently developing an android app, there is always unexpected exception popup when I use AsyncTask or Thread. any one tell me what's the difference between them and how to use them ?

user418751
  • 1,937
  • 2
  • 18
  • 21

5 Answers5

2
"there is always unexpected exception popup when I use AsyncTask or Thread."

It depends on how to use them, and your code inside it. Mostly when you are using Main UI Thread in this (other) thread or asynctask in-properly.

For difference between AsyncTask and Thread you have to search on SO and net. You can find easily it.

Anyway I recommended you to just go through this blog Android Thread Constructs(Part 4): Comparisons

And this SO question Difference between Service, Async Task & Thread?

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • If we can perform our function and can do our task with Async Task, then why we need Thread. I am confused, that if every thing is possible with Async Task, and it is good to use, then what is the main purposes of thread which differentiate it from Async Task??? please clear me – Pir Fahim Shah Apr 15 '14 at 11:01
0

You really need to read this properly.

http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html

Shubhayu
  • 13,402
  • 5
  • 33
  • 30
0

Mostly use AsyncTask - it's a dressed-up Thread that allows you to among other things interact with the GUI at the beginning, at the end and to report progress in a controlled manner. If you're really feeling like using a Thread, use IntentService instead.

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
0

its a very good question and must considered before start using one of them please go through this Difference between Service, Async Task & Thread?

Community
  • 1
  • 1
vipin
  • 2,851
  • 4
  • 18
  • 32
0

There is a big difference between AsyncTask and Thread, i.e.

Thread can be triggered from any thread, main/UI or background; but AsyncTask must be triggered from main thread.

Also on lower api of android(not sure, may be api level < 11), one instance of AsyncTask can be executed only once.

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111