Programming Android with Kotlin

Book description

Android development is so vast that mastering this mobile operating system can seem daunting--particularly now that Kotlin has become the official Android development language. This book helps Android developers make the transition from Java to Kotlin and shows them how Kotlin provides a true advantage for gaining control over asynchronous computations.

By focusing specifically on coroutines, a new asynchronous programming paradigm, this book describes how you can achieve structured concurrency with Kotlin. Authors Pierre-Oliver Laurence, Amanda Hinchman-Dominguez, and Mike Dunn provide implementations of the most common tasks in native Android development.

  • The basics of the Kotlin language and the Android architecture
  • Data transformations in Kotlin
  • Android fundamentals in memory and threading
  • Concurrency with coroutines
  • Channels and flows
  • Android profiling tools

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Guidelines and Recommendations for reading this book
    2. What to expect
  2. 1. Handling Concurrency with the Callback Pattern
    1. Example of purchase feature
    2. The architecture
    3. Creating the app
      1. View-model
      2. View
      3. Implement the logic
      4. Discussion
      5. Structured concurrency
      6. Memory leaks
    4. Limitations of the threading model
    5. Summary
  3. 2. Coroutines concepts
    1. What exactly is a coroutine?
      1. Your first coroutine
      2. The async coroutine builder
    2. A quick detour about Structured Concurrency
      1. The parent-child relationship in structured concurrency
    3. CoroutineScope and CoroutineContext
    4. Suspending functions
    5. Suspending functions under the hood
    6. Using coroutines and suspending functions, a practical example
      1. Don’t be mistaken about the suspend modifier
    7. Summary
  4. 3. Structured Concurrency with Coroutines
    1. Suspending functions
      1. Traditional approach using java.util.concurrent.ExecutorService
      2. Using suspending functions and coroutines
    2. Cancellation
      1. Coroutine lifecycle
      2. Cancelling a coroutine
      3. Cancelling a task delegated to a third-party library
      4. Coroutines which are cooperative with cancellation
      5. Handling cancellation
      6. Causes of cancellation
    3. Supervision
      1. supervisorScope builder
    4. Parallel decomposition
    5. Exception handling
      1. Unhandled vs Exposed exceptions
      2. Exposed exceptions
      3. Unhandled exceptions
    6. Summary
  5. 4. Channels
    1. Channels overview
      1. Rendez-vous Channel
      2. Unlimited Channel
      3. Conflated Channel
      4. Buffered Channel
      5. Channel producers
    2. Communicating Sequential Processes
      1. Model and Architecture
      2. A first implementation
      3. The select expression
      4. Putting it all together
      5. Performance test
      6. Back Pressure
      7. Similarities with the Actor model
      8. Final thoughts
    3. Deadlock in CSP
    4. Limitations of channels
      1. Channels are hot
    5. Summary

Product information

  • Title: Programming Android with Kotlin
  • Author(s): Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, Mike Dunn
  • Release date: August 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492063001