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,500 courses taught by industry experts.

Challenge: Run multiple coroutines in a ViewModel

Challenge: Run multiple coroutines in a ViewModel

(light music) - [Instructor] In a previous challenge, I asked you to use Java threads to manage the animation of a dice rolling application. When you touch the button, there's a loop happening creating multiple threads running simultaneously. But here's the thing about the app I'm showing you right now. It's not using the thread class. Instead, it's using co-routines, and it's using them inside a view model. So that's your challenge. Take this version of the application. This is my version of the finished app from the last challenge. Right now, there's a handler that's receiving messages, and the handler's messages are being sent from within threads. The challenge is to create a view model class and attach it to the activity, and then migrate all this code over to the view model. Publish the new values. In order to share that data with the main activity, you'll need to wrap two values in an object. The index of…

Contents