droidcon Aug 4, 2025

Cancellable Flows in Kotlin Coroutines: The Complete Guide

Article Summary

Kotlin Flow cancellation isn't just calling cancel() and hoping for the best. Sahil Thakar breaks down 11 sophisticated techniques that prevent memory leaks and save battery life.

This comprehensive guide from droidcon explores Flow cancellation in Kotlin Coroutines, covering everything from basic job cancellation to advanced operators like transformWhile and collectLatest. Each technique includes practical code examples and real-world use cases.

Key Takeaways

Critical Insight

Choosing the right Flow cancellation technique based on your use case (lifecycle management, timeouts, conditions, or count limits) dramatically improves Android app performance and resource management.

The article reveals a critical difference between first() and single() that could save you from production bugs, plus a search implementation pattern that cancels outdated API calls automatically.

Recent from droidcon

Related Articles