
Explore Kotlin coroutines for Android through a structured learning cycle of intuitive explanations, hands-on exercises, and repeated mastery of core concepts like cancellation.
Learn how the Udemy course review system prompts an early rating popup and why timely ratings matter for the Kotlin Coroutines for Android Masterclass.
Observe how a five-second ui thread benchmark blocks the main thread, delaying remaining time updates and highlighting the need for concurrency.
Explore concurrency in Android apps by using the Kotlin coroutines framework to run multiple tasks simultaneously, manage dependencies, and avoid UI thread bottlenecks.
Discover how to introduce concurrency with a bare thread, run a benchmark off the UI thread, and post results to the main thread using a handler and looper.
Learn how to use Kotlin coroutines to switch between UI and background threads, using coroutine scope, dispatchers, with context, and suspending functions.
Learn how to correctly use coroutines to manage concurrency, fix mistakes that enable UI interactions during a long running benchmark, and ensure a suspending function completes before UI state updates.
Apply coroutines in exercise one by offloading a get reputation call to a background thread, using a fragment and a fake endpoint, and observe a responsive ui with toast updates.
Explore a Kotlin coroutines solution for exercise one, including a solutions package, a solution fragment, suspending functions, and a coroutine scope with main and default dispatchers to fetch user reputation.
Learn how to cancel coroutines in Android by tracking a job from launch, canceling it on stop, and understanding collaborative cancellation with withContext.
Cancel the running coroutine in exercise two to avoid UI side effects when the app goes to background, by copying the cancellation code into the fragment and preserving toast behavior.
Learn to manage a nullable coroutine job in a fragment for exercise two, cancel it on stop to prevent the toast after backgrounding, and avoid crashes from require context.
Refactor a concurrent coroutines fragment from legacy handler to suspend functions, using delay and a two-coroutine approach to achieve concurrency, and cancel updates on stop to respect lifecycle.
Learn how suspension differs from blocking in Kotlin coroutines by comparing delay with thread.sleep on the main thread, and see two coroutines run concurrently without blocking the UI.
Cancel all coroutines in a scope with a single call, instead of tracking each job, to achieve clean shutdown on onStop and avoid lingering activity.
Work through exercise three by timing the get reputation for user flow in a fragment, showing elapsed time in a text view, and managing two concurrent coroutines with cancellation on stop.
Demonstrates a concurrent elapsed time counter using a coroutine in a scope, updating every 100 milliseconds and canceling on fragment stop and flow completion.
Summarizes core coroutines concepts, including sequential steps across multiple dispatchers, suspending functions, and scope-based cancellation on the main UI thread.
Explore how to cancel a coroutine scope by canceling the entire scope versus its children, and learn when to apply each approach in Kotlin for Android.
Compare scope cancellation with scope's children cancellation in Kotlin coroutines, illustrated through practical demos. See why canceling the entire scope can block new coroutines, while canceling only children allows reuse.
Learn to manage coroutines inside a ViewModel, distinguishing canceling scope children from canceling the entire scope. See how onCleared cancels remaining coroutines to prevent memory leaks during navigation.
Learn to use the view model scope extension from Kotlin extensions for ViewModel to manage coroutines in view models, with automatic cancellation when the view model is cleared.
Cancel children using coroutine context cancelChildren; this cancels all child coroutines, while canceling the entire scope disables future launches. Avoid full scope cancellation to prevent silent failures and tricky bugs.
Explore what structured concurrency means in Kotlin coroutines, with intuitive explanations and practical terms, and see Kotlin examples that leverage it to simplify tasks.
Offload Fibonacci computation to a background thread using an async approach with a callback. Learn concurrency handling and the perils of testing asynchronous code and flaky tests.
Learn how a Fibonacci use case async offloads computation to a background thread and notifies on the UI thread, exposing flaky tests and the need for a better testing approach.
Showcases the thread poster library to offload work to a background thread and return results to the UI thread, with test doubles enabling reliable multithreaded Fibonacci unit tests.
Explore structured concurrency in unit testing, from synchronous tests to thread poster and UI thread emulation, and learn how Kotlin coroutines enable production-ready concurrency.
Explore structured concurrency in Kotlin by refactoring a Fibonacci use case to coroutines, using a coroutine scope and dispatchers to manage background and main threads.
Explore structured concurrency with Kotlin coroutines by transforming a Fibonacci use case into suspending functions, demonstrating how to run computations on a background dispatcher while keeping the user interface responsive.
Explore structured concurrency and concurrent unit testing by implementing and validating a complex factorial use case with multithreaded computation across processors, through exercise four.
Examine a Kotlin coroutines-based factorial use case, create and adapt unit tests, and demonstrate structured concurrency with runBlocking to simplify testing of concurrent code in Android apps.
Explore structured concurrency with Kotlin coroutines, pausing and waiting for ancestor to complete, using blocking or suspending calls to ensure all concurrent flows finish.
Explore the design of concurrent code in Android, and learn how presentation layer logic must run on the UI thread exclusively, avoiding multithreading in activities, fragments, and controllers.
Encapsulate concurrency inside a benchmark use case to keep the presentation layer on the UI thread, using dependency injection and a composition root so callers need not manage threads.
Extract the get reputation for user function into a dedicated get reputation use case by injecting the endpoint, hiding it behind the use case, and refactoring the fragment.
Design clean, maintainable Android code by keeping presentation logic on the UI thread, and use case classes to encapsulate concurrent flows across MVC, MVVM, and MVP patterns.
Explore Kotlin coroutines dispatchers in Android, learn how dispatchers assign coroutine code to threads, and review main, main immediate, default, io, and unconfined dispatchers and their purposes.
Explore how the main dispatcher and main immediate differ in Kotlin coroutines for Android, and learn their effects on the UI thread, handler, and run on UI thread behavior.
Use default dispatchers for computation intensive work, backed by a thread pool that expands with cores; use io dispatchers for io waiting tasks, which can use up to 64 threads.
Explore the unconfined dispatcher in Kotlin coroutines, observing immediate execution on the calling thread often the main thread, and why Android apps should avoid it.
Use a single custom unbounded coroutine dispatcher for background work in Android apps. This simplifies concurrency by avoiding default and IO dispatchers in most cases, with a straightforward background dispatcher.
Explore cooperative cancellation in Kotlin coroutines and learn why canceling code and the canceled code must cooperate to stop concurrent processes safely. Understand how to gain control over cancellation timing.
Explore cooperative cancellation in Kotlin coroutines by making long-running benchmarks cancel gracefully with isActive checks, handling CancellationException, and leveraging structured concurrency for clean, timely cleanup.
Understand cooperative cancellation in Kotlin coroutines by examining how canceling code interacts with the code being canceled, using the coroutine context, isActive, and ensureActive to throw cancellation exceptions when needed.
uncover a fragment lifecycle bug in coroutine cancellation that crashes when detaching after cancellation, and fix by checking for non-null context or lifecycle state before toasts.
In exercise 6, implement a cancellation strategy for a benchmark flow that now posts results to a remote endpoint, aligning with business requirements while respecting the post benchmark results class.
Demonstrates clean cancellation of a benchmark use case in a Kotlin Coroutines for Android Masterclass, showing how to use ensureActive to prevent partial data and avoid server corruption.
Learn how to use non-cancellable blocks in Kotlin coroutines to make server-side updates and local state changes atomic, ensuring the user interface stays consistent even when cancellations occur.
Master cooperative cancellation in Kotlin coroutines by choosing appropriate strategies, balancing cancelable and non cancelable code, and preventing data issues during cancellation.
Explore the roles and interrelationships of the main building blocks—coroutine scope, context, dispatcher, and job—and how they integrate to enable structured concurrency in Kotlin coroutines for Android.
Explore how coroutine scope and coroutine context create and manage a job, use runBlocking and join to enforce structured concurrency, and understand the default dispatcher in Kotlin coroutines.
Explore how coroutine context elements like dispatcher, name, and id shape coroutine scopes and launches. Learn to override context elements to control dispatchers and naming for easier debugging.
The withContext function modifies coroutine context to create a new scope. It replaces elements without spawning a new coroutine, enabling structured concurrency.
Explore the coroutines jobs hierarchy, illustrating a root scope with child coroutine and a with-context block, and how parent-child relationships enable structured concurrency and cancellation propagation.
Explore how the Kotlin coroutines jobs hierarchy drives cancellation propagation from a top-level scope to leaf nodes, and how cancellation exceptions propagate back to the parent.
Explore how non-cancellable blocks break the job hierarchy, how cancellation signals propagate in with context, and how structured concurrency remains intact in coroutine hierarchies.
Explore exercise seven by implementing tests for nested withContext blocks, nested launches, and outer-scope launches to analyze jobs hierarchy, cancellation, and structured concurrency in Kotlin coroutines.
Explore nested with context blocks, cancellation, and structured concurrency in Kotlin coroutines. Compare launching new coroutines within the same scope versus an external scope, and analyze job hierarchies.
Demonstrates the mistake of joining a scope job in nested launches. Shows how joining the child coroutine’s job fixes unit tests that would hang, ensuring all tests complete.
Explore coroutine mechanics, including coroutine scope and context, dispatchers, and jobs, and learn how nested coroutines create concurrency with structured concurrency and non-cancelable with context.
Learn how to convert sequential steps into parallelized algorithms using coroutines for practical Android applications. Understand that concurrency and parallelism are effectively the same for most practical use.
The lecture explains implementing parallel decomposition in fetch and cache users to run per-user tasks concurrently, handling coroutine cancellation safely, and fixing a bug related to elapsed time updates.
See a practical solution to exercise eight using parallel coroutines for user details with structured concurrency, and learn to make cleanup non-cancelable to prevent race conditions during cancellation.
Explore how parallel decomposition with Kotlin coroutines on Android can fail when using shared mutable state and atomicity issues. See how nondeterministic results from increments expose concurrency bugs to avoid.
Explore how the async coroutine builder returns a deferred result, enabling concurrent tasks without shared mutable state, and learn patterns like awaiting all and summing results for safe concurrency.
Parallelize data fetching in exercise nine's fragment, return the list of users to bind to the text view, and fix the cancellation bug for concurrent user interface updates.
The lecture presents exercise 9 solution, implementing parallel decomposition with async and awaitAll to fetch users, map IDs to users, and display user names, using non-cancelable withContext for cancellation safety.
Explore parallel decomposition with Kotlin coroutines to speed Android apps, using launch for side effects and async for results, while avoiding shared mutable state to prevent concurrency bugs.
Study exceptions handling in coroutines, distinguishing uncaught exceptions as errors and the special cancellation exception that cancels the parent coroutine, with practical examples and exercises.
Explore what happens when an uncaught exception in a coroutine crashes an Android login flow, with a timed-out endpoint and discussion of shared mutable state and atomic integers.
Explore how CoroutineExceptionHandler governs uncaught exceptions in Kotlin coroutines, with unit-test demos showing installation in coroutine context and the difference from Android's default crash behavior.
Explore how an uncaught exception in concurrent coroutines cancels the enclosing scope and all children, and how a coroutine exception handler still leads to scope cancellation.
Learn to prevent cancellation of a parent coroutine scope using supervisor job, isolating child failures, and handling exceptions with a custom coroutine exception handler.
Propagate the exception from the login use case to the coroutine scope in exercise ten and handle it at the scope level to prevent crashes and keep the app functional.
Demonstrates my solution to exercise ten by adding a custom coroutine exception handler and a supervisor scope to prevent crashes and preserve login flow.
Compare uncaught exceptions in launch and async coroutines, noting that async delays exception handling until await, and show how to use supervisor job and try/catch to manage it.
learn the correct way to handle exceptions in coroutines by catching timeouts inside the login use case, preventing propagation to the presentation layer.
This course is your complete guide into the world of Kotlin Coroutines in Android. By the end of this course, you'll know how to use Coroutines to write reliable, maintainable and responsive Android applications.
The philosophy of this course is "learn by coding", so you'll be asked to solve a series of carefully designed, hands-on exercises. These exercises are built into a tutorial Android application, so they accurately reflect the "real world" use cases that you'll encounter in real Android apps.
Even though the main goal of this course is to give you practical skills, it also covers the theory behind Kotlin Coroutines framework at a more conceptual level. In particular, you're going to learn what Structured Concurrency is, what benefits it provides and how Coroutines support this powerful paradigm.
These aspects of Kotlin Coroutines framework are covered in this course:
Coroutines as concurrency framework
Suspending vs blocking functions
Coroutine Scope, Context and Jobs hierarchy
Coroutines cancellation
Exceptions handling inside Coroutines
Structured Concurrency
Unit testing with Coroutines
and more...
In this course we go beyond the functionality of Kotlin Coroutines framework itself and also discuss important design considerations that will help you write clean and maintainable code.
Knowledge of Kotlin Coroutines is an essential skill for Android developers. After completing this course, you'll be able to use Coroutines in real-world Android projects, and you'll be ready to answer even the trickiest questions about this framework in job interviews.
So, if you're serious about Android development and you want to master Kotlin Coroutines, this course is perfect for you!