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.

Switch between foreground and background threads

Switch between foreground and background threads

- [Narrator] When you launch a Coroutine the Dispatcher determines whether you're working in the UI thread or in a background thread. But it's possible to switch back and forth between threads in the middle of the Coroutine. Without Coroutines, you'd need to create callbacks or send messages to communicate between the threads. But in a Coroutine, your code can be sequential and all in one place. In this branch of the repository, I've added a constant at the top of the class. This is a URL where I've placed a file. I'll copy that URL to the clipboard, then I'll go to a browser window and paste it in and show that this is just a text file with some placeholder text. In order to download that from the web my app needs the appropriate permission. So I'll go to the manifest file and I'll add a user's permission element and I'll add the permission for the internet. This is a normal permission so it will be granted…

Contents