Method definition:
"Performs the action specified in the UI Thread. If the current Thread is the
Thread of the UI, then the action will be executed immediately. If the Thread
current is not from the UI, the action is thrown in the event queue. "
So let's go:
- How does this method become a repetitive process to the point of replacing the handler? How does this method work?
I believe it does not replace Handler
because they have different features!
The
runOnUiThread
, sends a
Runnable
to run on the UI Thread, while
Handler
, executes a
Runnable
at a future time (predefined) or executes this
Runnable
on a
Thread
different (not just UI as
runOnUiThread
).
-
I would like to understand the operation of this method and the need to implement Runnable () within this method
I believe the above definition explains its operation!
Now let's set the Runnable
:
The Runnable interface should be implemented by any class whose
instances are meant to be run by a Thread.
We use Runnable
to encapsulate and send the code we want to transfer to run on another Thread
.
runOnUiThread method documentation
Handler Class Documentation
Runnable Interface Documentation