0%

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

Table of Contents

  1. 1. Thread Safety
    1. An example of thread issue
    2. Invariants
    3. Mutexes
    4. Thread-safe collections
    5. Thread confinement
    6. Thread contention
    7. Blocking call versus Non-Blocking call
    8. Work queues
    9. Back pressure
    10. Summary
  2. 2. Handling Concurrency using callbacks
    1. Example of purchase feature
    2. Creating the app
    3. View-model
    4. View
    5. Implement the logic
    6. Discussion
    7. Limitations of the threading model
    8. Summary
  3. 3. Coroutines concepts
    1. What exactly is a coroutine?
    2. Your first coroutine
    3. The async coroutine builder
    4. A quick detour about Structured Concurrency
    5. The parent-child relationship in structured concurrency
    6. CoroutineScope and CoroutineContext
    7. Suspending functions
    8. Suspending functions under the hood
    9. Using coroutines and suspending functions, a practical example
    10. Don’t be mistaken about the suspend modifier
    11. Summary
  4. 4. Structured Concurrency with Coroutines
    1. Suspending functions
    2. Traditional approach using java.util.concurrent.ExecutorService
    3. Using suspending functions and coroutines
    4. Cancellation
    5. Coroutine lifecycle
    6. Cancelling a coroutine
    7. Cancelling a task delegated to a third-party library
    8. Coroutines which are cooperative with cancellation
    9. Handling cancellation
    10. Causes of cancellation
    11. Supervision
    12. supervisorScope builder
    13. Parallel decomposition
    14. Exception handling
    15. Unhandled vs Exposed exceptions
    16. Exposed exceptions
    17. Unhandled exceptions
    18. Summary
  5. 5. Channels
    1. Channels overview
    2. Rendez-vous Channel
    3. Unlimited Channel
    4. Conflated Channel
    5. Buffered Channel
    6. Channel producers
    7. Communicating Sequential Processes
    8. Model and Architecture
    9. A first implementation
    10. The select expression
    11. Putting it all together
    12. Fan-out and Fan-in
    13. Performance test
    14. Back Pressure
    15. Similarities with the Actor model
    16. Final thoughts
    17. Deadlock in CSP
    18. Limitations of channels
    19. Channels are hot
    20. Summary
  6. 6. Flows
    1. An introduction to Flows
    2. Operators
    3. Terminal operators
    4. Examples of cold flow usage
    5. Use case #1: Interface with a callback-based API
    6. Use-case #2: Concurrently transform a stream of values
    7. Use case #3: Create a custom operator
    8. Error handling
    9. The try/catch block
    10. The catch operator
    11. Materialize your exceptions
    12. Hot flows with SharedFlow
    13. Using SharedFlow to stream data
    14. Using SharedFlow as an event-bus
    15. StateFlow, a specialized SharedFlow
    16. Summary
  7. 7. Performance Considerations with Android Profiling Tools
    1. Android Profiler
    2. Network Profiler
    3. CPU Profiler
    4. Energy Profiler
    5. Memory Profiler
    6. Detecting Memory Leaks with LeakCanary
    7. Summary
3.133.147.252