Kotlin for Android App Development

Book description

Write More Robust and Maintainable Android Apps with Kotlin


“Peter Sommerhoff takes a practical approach to teaching Kotlin by providing a larger set of code listings that demonstrate language features and by guiding readers through the development of two Android apps step by step. . . . Peter finds a good balance between what is essential and what can be left to readers, so this book is an efficient yet comprehensible source for starting programming with Kotlin.”

–;Bernhard Rumpe, Professor of Software Engineering, RWTH Aachen University

The Kotlin language brings state-of-the-art programming techniques and constructs to Android development. Kotlin for Android App Development will help you rapidly understand Kotlin's principles and techniques, apply Kotlin in production app development, integrate Kotlin with existing Java code, and plan a migration to Kotlin, if you choose.


If you have at least basic programming experience (with any language), Peter Sommerhoff's well-crafted overview and examples will help you get quickly up-to-speed with the Kotlin language, its constructs, and its advanced functional and object-oriented capabilities.


Once you've mastered these foundations, Sommerhoff walks you through two complete app development projects, introducing best practices and emerging patterns for writing code that's robust, concise, readable, and highly performant.

  • Understand Kotlin's goals, principles, advantages, design, and constructs
  • Take full advantage of functional programming in the Kotlin environment
  • Write more concise and reusable code using Kotlin's object-oriented features
  • Interoperate with existing Java code, and plan a migration to Kotlin
  • Use coroutines to efficiently handle concurrency
  • Capture data via third-party APIs, map it to internal data representations, and present it to users
  • Master best practices for architecting Kotlin Android apps
  • Improve productivity and readability by creating simple domain-specific languages in Kotlin

Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details.

Table of contents

  1. Cover Page
  2. About This E-Book
  3. Title Page
  4. Copyright Page
  5. Contents
  6. Listings
  7. Foreword
  8. Preface
    1. Who This Book Is For
    2. How to Follow This Book
    3. Book Conventions
  9. Acknowledgments
  10. About the Author
  11. I Learning Kotlin
    1. 1 Introducing Kotlin
      1. What Is Kotlin?
      2. Goals and Language Concepts
      3. Why Use Kotlin on Android?
      4. Kotlin versus Java 8
      5. Tool Support and Community
      6. Business Perspective
      7. Who’s Using Kotlin?
      8. Summary
    2. 2 Diving into Kotlin
      1. Kotlin REPL
      2. Variables and Data Types
      3. Conditional Code
      4. Loops and Ranges
      5. Functions
      6. Null Safety
      7. Equality Checks
      8. Exception Handling
      9. Summary
    3. 3 Functional Programming in Kotlin
      1. Purpose of Functional Programming
      2. Functions
      3. Lambda Expressions
      4. Higher-Order Functions
      5. Working with Collections
      6. Scoping Functions
      7. Lazy Sequences
      8. Summary
    4. 4 Object Orientation in Kotlin
      1. Classes and Object Instantiation
      2. Properties
      3. Methods
      4. Primary and Secondary Constructors
      5. Inheritance and Overriding Rules
      6. Type Checking and Casting
      7. Visibilities
      8. Data Classes
      9. Enumerations
      10. Sealed Classes
      11. Objects and Companions
      12. Generics
      13. Summary
    5. 5 Interoperability with Java
      1. Using Java Code from Kotlin
      2. Using Kotlin Code from Java
      3. Best Practices for Interop
      4. Summary
    6. 6 Concurrency in Kotlin
      1. Concurrency
      2. Kotlin Coroutines
      3. Summary
  12. II Kotlin on Android
    1. 7 Android App Development with Kotlin: Kudoo App
      1. Setting Up Kotlin for Android
      2. App #1: Kudoo, a To-Do List App
      3. Summary
    2. 8 Android App Development with Kotlin: Nutrilicious
      1. Setting Up the Project
      2. Adding a RecyclerView to the Home Screen
      3. Fetching Data from the USDA Nutrition API
      4. Mapping JSON Data to Domain Classes
      5. Introducing a ViewModel for Search
      6. Letting Users Search Foods
      7. Introducing Fragments I: The Search Fragment
      8. Introducing Fragments II: The Favorites Fragment
      9. Store User’s Favorite Foods in a Room Database
      10. Fetching Detailed Nutrition Data from the USDA Food Reports API
      11. Integrating the Details Activity
      12. Storing Food Details in the Database
      13. Adding RDIs for Actionable Data
      14. Improving the User Experience
      15. Summary
    3. 9 Kotlin DSLs
      1. Introducing DSLs
      2. Creating a DSL in Kotlin
      3. DSL for Android Layouts with Anko
      4. DSL for Gradle Build Scripts
      5. Summary
    4. 10 Migrating to Kotlin
      1. On Software Migrations
      2. Leading the Change
      3. Partial or Full Migration
      4. Where to Start
      5. Tool Support
      6. Summary
    5. A Further Resources
      1. Official Resources
      2. Community
      3. Functional Programming
      4. Kotlin DSLs
      5. Migrating to Kotlin
      6. Testing
  13. Credits
  14. Glossary
  15. Index

Product information

  • Title: Kotlin for Android App Development
  • Author(s): Peter Sommerhoff
  • Release date: December 2018
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780134854281