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
From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines
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
-
-
-
-
-
(Locked)
Define and run a simple coroutine4m 47s
-
(Locked)
Switch between foreground and background threads4m 23s
-
(Locked)
Run coroutines in a ViewModel class5m 23s
-
(Locked)
Cancel coroutines with a job reference3m 40s
-
(Locked)
Challenge: Run multiple coroutines in a ViewModel2m 28s
-
(Locked)
Solution: Run multiple coroutines in a ViewModel3m 34s
-
(Locked)
-
-
-