From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Define and run a Runnable object

Define and run a Runnable object

- [Instructor] A thread, in its simplest form, is a linear sequence of actions. First do this, then that, and so on. Android's user interface runs in a single thread and it has a first in first out operation stack. When you run code without doing anything to indicate the order of execution, the operations will be executed in the order in which they're declared, and each operation can only be executed once the previous operation is complete. In this application, I'll add code to my run code function, I'll get rid of this comment, and then I'll add code to output a simple message of synchronous operation one. I'll duplicate that twice and change the numbers and I'll run the code. I'll touch the clear button and then run the code and the result is the operations output, one at a time. Now, I want to define an operation that will always be executed at the end of the stack. I'll do that by creating something called a…

Contents