Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android runnable difference

What is the different b/w running runnable inside handler new Handler().post(runnable) and running in Thread(runable) ?

like image 319
d-man Avatar asked Dec 23 '22 06:12

d-man


1 Answers

Handler is used for communication between and coordinating threads. By creating a Handler, you bind it to the current thread. If you post a runnable to that Handler, it will be executed in that same thread.

Thread is Java's way to spawn new user-level threads. The runnable you pass it will be executed in that thread.

The two concepts are not mutually exclusive. You can use Handler with custom Threads.

like image 167
Matthias Avatar answered Dec 31 '22 12:12

Matthias