Does handler.post (runnable) create a new thread?

If a handler was created in the main user interface thread, does the message with Runnable create a child thread that is added to the message queue, or does it just start in the user interface thread?

handler.post(new Runnable(){
    public void run() {
        // do stuff
    }
});
+5
source share
2 answers

No, it does not create a new thread. It just executes your runnable on the thread your handler is attached to, which in this case means your UI thread

+11
source
handler.post(new Runnable()){

public  void run(){
//do something
}
});

this does not guarantee that it will create a new thread.it, it will just call the runnable thread in which the handler is attached (the UI thread is here).

, , ( ), , .

0

All Articles