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.
Solution: Run multiple background tasks with threads
From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines
Solution: Run multiple background tasks with threads
(upbeat music) - [Narrator] In a previous video I invited you to improve the application that rolls the dice so that instead of simply showing five randomized values, when the user touches the roll button, they see an animation. Each of the dice are changing values 20 times, and at the end of two seconds or so, you see the randomized values appear. Here's how I solved this problem. I'm now on branch 206 for this video, and the first thing I did was to move my array declarations to the top of the class so that they'd be visible to all the functions within the class. The array that contains references to my drawable resources just had to be moved. No other changes. For the image views, though, I needed to declare that variable with the late in it key word at the top of the class and then I initialized the image views array down here after I've gotten a reference to my view binding with activity main binding dot…
Contents
-
-
-
-
(Locked)
Define and run a Runnable object4m 40s
-
(Locked)
Delay execution of a Runnable object3m 42s
-
Manage background tasks with threads5m 22s
-
(Locked)
Send a message to the UI from a background thread6m 6s
-
(Locked)
Challenge: Run multiple background tasks with threads3m 28s
-
(Locked)
Solution: Run multiple background tasks with threads3m 40s
-
(Locked)
-
-
-
-