Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performance wise, what is better: AsyncTask or simply create a runnable? [closed]

I am currently working on an Android project which loads a lot of pictures onCreate. To make sure the UI doesn't get blocked I have the option to put it in a runnable or an AsyncTask. What is (performance wise) the better option or is it practically the same?

like image 213
Bart Burg Avatar asked Jan 31 '26 20:01

Bart Burg


2 Answers

Yes it's more or less the same.AsyncTask is nothing else than an convenience-class for Runnable/Thread.

In my opinion you should use AsyncTask. It's kind of an android standard plus it takes the task away from you to check when the work is finished. You can easily make a callback in the onPostExecute or do whatever you want with the result. (Remeber that only doInBackGround runs in an own thread - the other methods run in the UI thread, so you can even add dialogs there and so on if you want.

like image 131
OschtärEi Avatar answered Feb 03 '26 09:02

OschtärEi


If you attach your Runnable on a new Thread then practically both would do the same under the hood. However, it is more easier to follow AsyncTask life-cycle and its the recommended way of doing parallel things in android. Therefore, my suggestion is to go with AsyncTask.

like image 31
waqaslam Avatar answered Feb 03 '26 11:02

waqaslam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!