Summary and Next Steps

Kotlin and Android Development featuring Jetpack — by Michael Fazio (37 / 125)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Handle AI Turns with Coroutines and First-Cla ss Functions | TOC | Chapter 5 Persist Game Data with Room 👉

We accomplished a lot in this chapter! We implemented all the game logic for Penny Drop plus connected the GameHandler to the UI. Plus, since the game logic is isolated in the GameHandler, our GameFragment and GameViewModel classes didn’t expand as much as they could have. That being said, keeping the state inside the GameViewModel class makes later code changes easier, as you’ll see next chapter.

Also, most of what we did in this chapter isn’t even Android-specific but rather illustrates how Kotlin can be used to write clearer code. Taking advantage of various language features like scope functions (.let {…} and .apply { … }), destructuring declarations, and when expressions can make your code more readable and maintainable. This goes for other Android apps as well as any non-Android Kotlin applications.

Now, the game works beautifully, but there’s one small issue: you can’t resume games if you close the app. Oh, and it doesn’t save the players from previous games. Or track any kind of stats. Actually, it doesn’t keep track of anything…

We could use some persistence in our app, and thankfully Jetpack has a great option for us: Room. Room is a wrapper over SQLite that makes database interaction much nicer. Next chapter, we’ll get…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.