0%

Start building native Android apps the modern way in Kotlin with Jetpack's expansive set of tools, libraries, and best practices. Learn how to create efficient, resilient views with Fragments and share data between the views with ViewModels. Use Room to persist valuable data quickly, and avoid NullPointerExceptions and Java's verbose expressions with Kotlin. You can even handle asynchronous web service calls elegantly with Kotlin coroutines. Achieve all of this and much more while building two full-featured apps, following detailed, step-by-step instructions.With Kotlin and Jetpack, Android development is now smoother and more enjoyable than ever before. Dive right in by developing two complete Android apps.

With the first app, Penny Drop, you create a full game complete with random die rolls, customizable rules, and AI opponents. Build lightweight Fragment views with data binding, quickly and safely update data with ViewModel classes, and handle all app navigation in a single location. Use Kotlin with Android-specific Kotlin extensions to efficiently write null-safe code without all the normal boilerplate required for pre-Jetpack + Kotlin apps. Persist and retrieve data as full objects with the Room library, then display that data with ViewModels and list records in a RecyclerView.

Next, you create the official app for the Android Baseball League. It's a fake league but a real app, where you use what you learn in Penny Drop and build up from there. Navigate all over the app via a Navigation Drawer, including specific locations via Android App Links. Handle asynchronous and web service calls with Kotlin Coroutines, display that data smoothly with the Paging library, and send notifications to a user's phone from your app.

Come build Android apps the modern way with Kotlin and Jetpack!



What You Need:

You'll need the Android SDK, a text editor, and either a real Android device or emulator for testing. While not strictly required, it's assumed you're using Android Studio, which comes with the Android SDK and simplifies creating an emulator. Also, a few examples require JDK 1.8 or later, though all of these pieces can be completed in other ways when using JDK 1.6.

Table of Contents

  1.  Acknowledgments
  2.  Preface
  3.  Introduction
    1. Who Is This Book For
    2. If You’re New to Android and/or Kotlin
    3. How to Read This Book
    4. Development Tips for the Book
    5. Online Resources
    6. Ready to Go?
  4. Part I. Penny Drop
    1. 1. Initialize the Penny Drop App
    2. How to Play Penny Drop
    3. Create the App
    4. What Else Do We Need?
    5. Summary and Next Steps
    6. 2. Build Views with Fragments
    7. Build a Fragment (Pick Players)
    8. Add Data Binding to the App
    9. Build Another Fragment (Game)
    10. Summary and Next Steps
    11. 3. Bind Data with ViewModels
    12. Create a ViewModel (Pick Players)
    13. Bind ViewModel to a Fragment (Pick Players)
    14. Add AI Spinner to Player List Items
    15. Customize the Player List Items
    16. Create Another ViewModel (Game)
    17. Bind ViewModel to a Fragment (Game)
    18. Summary and Next Steps
    19. 4. Update LiveData with Conditional Game Logic
    20. Create GameHandler
    21. Start a Game
    22. More GameViewModel Functions: roll() and pass()
    23. Update the UI
    24. Create Turn Summary Text
    25. Handle AI Turns with Coroutines and First-Class Functions
    26. Summary and Next Steps
    27. 5. Persist Game Data with Room
    28. Add Room to the App
    29. Add a RoomDatabase Class
    30. Create a DAO Class
    31. Add Entity Classes
    32. Add Data During Database Creation
    33. Add Converters to the Database
    34. Create a Repository Class
    35. Access the Database from a ViewModel
    36. Update the UI Data Binding
    37. Summary and Next Steps
    38. 6. Build a List with RecyclerView
    39. Add the RecyclerView
    40. Build the List Item Layout
    41. Create a Custom ListAdapter
    42. Connect Adapter to RecyclerView
    43. Load Data into RecyclerView from Database
    44. Summary and Next Steps
    45. 7. Customize an App with Settings and Themes
    46. Add a New SettingsFragment
    47. Use Saved Preferences
    48. Add Themes
    49. Change Themes
    50. Add Night Mode Support
    51. Add an About the App Section
    52. Summary and Next Steps
  5. Part II. Android Baseball League
    1. 8. Initialize the Android Baseball League App
    2. Welcome to the Official ABL App
    3. Create the App
    4. Configure the Activity
    5. Add the First Fragment
    6. Summary and Next Steps
    7. 9. Navigate via Navigation Drawer
    8. Add the Navigation Drawer
    9. Add Fragments (Standings and Single Team)
    10. Pass Data with Safe Args
    11. Navigate Directly via a Deep Link
    12. Summary and Next Steps
    13. 10. Load and Save Data with Coroutines and Room
    14. Create a Database
    15. Work with Retrofit
    16. Load Data from External APIs
    17. Add a New Fragment (Scoreboard)
    18. Summary and Next Steps
    19. 11. Display Data with Paging
    20. Add Two New Fragments (Leaders and Single Player)
    21. Add a New Fragment (Players)
    22. Handle Paging Data in the App
    23. Display Paging Data in a RecyclerView List
    24. Summary and Next Steps
    25. 12. Personalize the Android Baseball League App
    26. Build a Settings Screen via Code
    27. Extract Colors with Palette
    28. Add and Group Additional Preferences
    29. Reliably Complete Background Work with WorkManager
    30. Summary and Next Steps
    31. 13. Send Info to and from the Android Baseball League App
    32. Alert Users with Notifications
    33. Send Cloud-Based Alerts with Push Notifications
    34. Share Links with Android Sharesheet
    35. Summary and Next Steps
  6. Part III. Test Your App
    1. 14. Unit Test Your App with JUnit
    2. Add Unit Tests
    3. Test a ViewModel Class
    4. Test a Data Access Object (DAO)
    5. Summary and Next Steps
    6. 15. Test Your App’s UI with Espresso
    7. Add UI Tests
    8. Add More UI Tests
    9. Summary and Next Steps
  7. Part IV. Appendixes
    1. A1. Install Android Studio
    2. Download Android Studio
    3. Install Android Studio
    4. Set Up an Android Virtual Device (AVD)
    5. A2. Troubleshooting Your App
    6. Debug Your App
    7. Display Messages with the Toast Class
    8. Log Messages to Logcat
    9. Wrapping Up
    10. A3. Gradle Dependencies
    11. Classpath Dependencies
    12. Implementation Dependencies
    13. KAPT Dependencies
    14. Test Dependencies
3.133.121.160