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

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