𝔖 Scriptorium
✦   LIBER   ✦

πŸ“

Programming Android with Kotlin: Achieving Structured Concurrency with Coroutines

✍ Scribed by Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, G. Blake Meike, Mike Dunn


Publisher
O'Reilly Media
Year
2021
Tongue
English
Leaves
465
Edition
1
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


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


Preface
Who Should Read This Book
Why We Wrote this Book
Navigating This Book
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgements
1. Kotlin Essentials
The Kotlin type system
Primitive types
Null safety
The Unit type
Function Types
Generics
Variables and Functions
Variables
Lambdas
Extension functions
Classes
Class initialization
Properties
lateinit properties
Lazy properties
Delegates
Companion Objects
Data Classes
Enum Classes
Sealed Classes
Visibility Modifiers
Summary
2. The Kotlin Collections Framework
Collection Basics
Java Interoperability
Mutability
Overloaded Operators
Creating Containers
Functional Programming
Functional vs Procedural: a simple example
Functional Android
Kotlin Transformation Functions
The Boolean Functions
Filter Functions
FlatMap
Grouping
Iterators vs. Sequences
An Example
The Problem
The implementation
Summary
3. Android Fundamentals
The Android stack
Hardware
Kernel
System Services
Android Runtime Environment
Applications
The Android Application Environment
Intents and Intent Filters
Context
Android Application Components: the Building Blocks
The Activity and its friends
Services
Content Providers
Broadcast Receivers
Android Application Architectures
MVC: the foundation
Widgets
The Local Model
Android Patterns
Model, View, Intent
Model, View, Presenter
Model, View, View Model
Summary
4. Concurrency in Android
Thread Safety
Atomicity
Visibility
The Android threading model
Dropped Frames
Memory leaks
Tools for Managing Threads
Looper/Handler
Executors and ExecutorServices
Tools for Managing Jobs
JobScheduler
WorkManager
Summary
5. Thread Safety
An example of thread issue
Invariants
Mutexes
Thread-safe collections
Thread confinement
Thread contention
Blocking call versus Non-Blocking call
Work queues
Back pressure
Summary
6. Handling Concurrency using callbacks
Example of purchase feature
Creating the app
View-model
View
Implement the logic
Discussion
Limitations of the threading model
Summary
7. Coroutines concepts
What exactly is a coroutine?
Your first coroutine
The async coroutine builder
A quick detour about Structured Concurrency
The parent-child relationship in structured concurrency
CoroutineScope and CoroutineContext
Suspending functions
Suspending functions under the hood
Using coroutines and suspending functions, a practical example
Don’t be mistaken about the suspend modifier
Summary
8. Structured Concurrency with Coroutines
Suspending functions
Traditional approach using java.util.concurrent.ExecutorService
Using suspending functions and coroutines
Cancellation
Coroutine lifecycle
Cancelling a coroutine
Cancelling a task delegated to a third-party library
Coroutines which are cooperative with cancellation
Handling cancellation
Causes of cancellation
Supervision
supervisorScope builder
Parallel decomposition
Exception handling
Unhandled vs Exposed exceptions
Exposed exceptions
Unhandled exceptions
Summary
9. Channels
Channels overview
Rendez-vous Channel
Unlimited Channel
Conflated Channel
Buffered Channel
Channel producers
Communicating Sequential Processes
Model and Architecture
A first implementation
The select expression
Putting it all together
Fan-out and Fan-in
Performance test
Back Pressure
Similarities with the Actor model
Final thoughts
Deadlock in CSP
Limitations of channels
Channels are hot
Summary
10. Flows
An introduction to Flows
Operators
Terminal operators
Examples of cold flow usage
Use case #1: Interface with a callback-based API
Use-case #2: Concurrently transform a stream of values
Use case #3: Create a custom operator
Error handling
The try/catch block
The catch operator
Materialize your exceptions
Hot flows with SharedFlow
Using SharedFlow to stream data
Using SharedFlow as an event-bus
StateFlow, a specialized SharedFlow
Summary
11. Performance Considerations with Android Profiling Tools
Android Profiler
Network Profiler
CPU Profiler
Energy Profiler
Memory Profiler
Detecting Memory Leaks with LeakCanary
Summary
12. Trimming Down Resource Consumption with Performance Optimizations
Achieving flatter view hierarchy with ConstraintLayout
Reducing Programmatic Draws with Drawables
Minimizing asset payload in network calls
Bitmap pooling and caching
Reducing unnecessary work
Using static functions
Minification & Obfuscation with R8 & Proguard
Summary
Index


πŸ“œ SIMILAR VOLUMES


Programming Android with Kotlin: Achievi
✍ Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, G. Blake Meike, Mike Dunn πŸ“‚ Library πŸ“… 2021 πŸ› O'Reilly Media 🌐 English

<div><p>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 tru

Programming Android with Kotlin: Achievi
✍ Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, G. Blake Meike, Mike Dunn πŸ“‚ Library πŸ“… 2022 πŸ› O'Reilly Media 🌐 English

<div><p>Developing applications for the Android mobile operating system can seem daunting, particularly if it requires learning a new programming language: Kotlin, now Android's official development language. With this practical book, Android developers will learn how to make the transition from Jav

Programming Android with Kotlin: Achievi
✍ Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, G. Blake Meike, Mike Dunn πŸ“‚ Library πŸ“… 2022 πŸ› O'Reilly Media 🌐 English

<div><p>Developing applications for the Android mobile operating system can seem daunting, particularly if it requires learning a new programming language: Kotlin, now Android's official development language. With this practical book, Android developers will learn how to make the transition from Jav

Programming Android with Kotlin: Achievi
✍ Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, G. Blake Meike, Mike Dunn πŸ“‚ Library πŸ“… 2021 πŸ› O'Reilly Media 🌐 English

Developing applications for the Android mobile operating system can seem daunting, particularly if it requires learning a new programming language: Kotlin, now AndroidΓ’??s officialdevelopment language. With this practical book, Android developers will learn how to make the transition from Java to Ko

Programming Android with Kotlin
✍ Pierre-Olivier Laurence; Amanda Hinchman-Dominguez; Mike Dunn πŸ“‚ Library πŸ“… 2021 πŸ› O'Reilly Media, Inc. 🌐 English