Definition of the method:
"Executes the action specified in the UI Thread. If the current Thread is the
UI thread, then the action will be executed immediately. If Thread
not currently in the UI, the action is launched in the event queue."
So come on:
- How does this method become a repetitive process to replace Handler? How does this method work?
I believe it does not replace Handler
, because they have different functionalities!
The runOnUiThread
, sends a Runnable
to run in the UI Thread, while the Handler
, executes a Runnable
in a future time (predefined) or executes this Runnable
in a Thread
different (not only the UI as the runOnUiThread
).
- I would like to understand how this method works and what is the need to implement Runnable() within this method
I believe the above definition explains how it works!
Now we come to the definition of Runnable
:
The Runnable interface must be implemented by any class whose
instances are intended to be executed by a Thread.
We use the Runnable
to encapsulate and send the code we want to transfer to be executed in another Thread
.
Documentation of the runOnUiThread method
Documentation of the Handler Class
Documentation of the Runnable interface
great explanation :) is that in the example of the book I saw it uses as a substitute for Handler... so that if it calls this method does not need a Handler for other things... thank you!
– Daniel Gentil
So that’s why I believe that does not replace, Handler has several uses, and one of it is very similar to what the 'runOnUiThread' method does!
– Thiago Luiz Domacoski