multi-threading in android | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

multi-threading in android

why in Android os, a thread can't access to UI thread and we should use message, handler, runOnUi, or something like? in Java does not exist this issue. So why it appears in Android API? Also explain how handler and runOnUi solve this problem?What techniques or codes do they use within themselves?

26th May 2021, 6:52 PM
Mehran
Mehran - avatar
1 Answer
+ 2
Apps on Android phones perform far better with multiple threads and very little done on the main UI thread because smart phones and tablets have many weak CPU cores instead of fewer but stronger CPU cores like on a full size desktop. There are more details on why multithreading is encouraged and forced in Android development here: https://developer.android.com/topic/performance/threads You might also want to look at this comparison between a few ways to run code in the UI thread: https://stackoverflow.com/questions/12850143/android-basics-running-code-in-the-ui-thread
13th Jun 2021, 10:44 PM
Josh Greig
Josh Greig - avatar