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?
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.
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.
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