PArth SOni
PArth SOni

Reputation: 117

run() And runOnUIThread() method internal difference

Can anyone explain internal mechanism of both this methods. What makes run corresponds only logic not ui and what makes runOnUiThread make UI changes possible.

Upvotes: 0

Views: 150

Answers (2)

ChrisBe
ChrisBe

Reputation: 908

run() is the interface method a Runnable implements

runOnUiThread(Runnable action) takes a Runnable which implements the run() method and executes it on the MainThread.

Views can only be changed from the MainThread therefore run() executed from every other thread will result in an error

Upvotes: 2

Darshan Pania
Darshan Pania

Reputation: 1414

runOnUiThread internally gets the Main or UI Thread and runs the code written inside it on the Main/UI thread.

run method initializes a new thread in the Executor Pool which is randomly assigned to it. Hence you cannot run UI changes code in a run method.

Upvotes: -1

Related Questions