0

I can see this always executing on the main thread.

Code sample :

private interface Task {
    void run() throws ListenerException;
}

private void runUITask(final Task task) {
    (new Runnable() {
        public void run() {
            task.run();
        }
    }).run();
}

Thank you in advance !!

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Rahul N
  • 11
  • There have to be clear shaped question and description. Please edit it in order to match the criteria. – Yordan Yanakiev Oct 27 '17 at 06:46
  • Possible duplicate of [What's the difference between Thread start() and Runnable run()](https://stackoverflow.com/questions/8579657/whats-the-difference-between-thread-start-and-runnable-run) – Alexei Levenkov Oct 27 '17 at 07:00
  • I don't think there is any queuing or threading in code shown... it looks like it will simply run the code as soon as `runUITask` is called. – Alexei Levenkov Oct 27 '17 at 07:01

2 Answers2

0

Runnable could be used along with handler when you want to give a certain amount of delay in execution of you piece of code.

Aditi
  • 389
  • 4
  • 13
0

Creating runnable creates a separate object with runs along with the main thread but you cannot update the UI using the runnable thread. The one advantage is you can update using a handler for the runnable. A Handler allows communicating back with UI thread from other background thread.Check this link for the differences.

http://android-codes-examples.blogspot.in/2011/03/how-to-run-runnable-thread-or-ui-thread.html

Sharath kumar
  • 4,064
  • 1
  • 14
  • 20