I am confused while trying to understand the Processes
and Threads
concepts in Android. Below I mention a few questions. Maybe those are stupid questions, but please help me answer to answer these questions and clarify my doubts.
1) If I create a thread where will it run? in Main(UI) Thread
?
2) If my created thread runs in the background as a worker Thread
then what is the use of AsyncTask
(I mean how it is better than thread)?
3)Can we create a Thread in AsyncTask?
1. If i create a thread where it will run? in Main(UI) thread/Worker Thread?
it will run in a Worker thread not in the Main Thread.
2.If my created thread runs on worker `Thread` then what is the use of `AsyncTask` (I mean how it is better than thread)?
AsyncTask
is used to communicate with the Main Thread..For example you are dowloading File from internet so here you want to update the Download progress in Your Activity
..for this AsyncTask better suits. You will update The Ui using onProgressUpdate()
method.So you can easily communicate with UI thread.
3)Can we create a thread in Async task?
Yes you can create it but it is useless because AsyncTask
has a doInBackGround()
method that already runs in a different Thread
so there is no need to create a new Thread
inside AsyncTask
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With