kotlin-flows

Guide Kotlin Coroutines Flow, StateFlow, and SharedFlow usage for asynchronous data streams.

119|14|Updated Mar 1, 2026
One-click install
npx skills add https://github.com/rcosteira79/android-skills --skill kotlin-flows
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-flows
Source: https://github.com/rcosteira79/android-skills/tree/main/skills/kotlin-flows
Command: npx skills add https://github.com/rcosteira79/android-skills --skill kotlin-flows

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you effectively use Kotlin's Flow, StateFlow, and SharedFlow for building reactive and asynchronous applications, ensuring efficient data streaming and state management.

Core Features & Use Cases

  • Flow Type Selection: Guides you in choosing between Flow, StateFlow, and SharedFlow based on your needs.
  • Operator Chains: Demonstrates how to use operators like map, filter, flatMapLatest, combine, etc.
  • Callback Bridging: Shows how to convert callback-based APIs into Flows.
  • Lifecycle-Safe Collection: Ensures flows are collected only when the UI is active.
  • Error Handling & Testing: Provides strategies for robust error management and testing Flows.
  • Use Case: You need to display a list of items that updates in real-time from a network source, and you want to ensure that UI updates are collected only when the screen is visible.

Quick Start

Use the kotlin-flows skill to create a StateFlow that emits the current user's name.

Frequently Asked Questions about kotlin-flows

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between StateFlow and SharedFlow for Kotlin state management?

Kotlin StateFlow is for representing and emitting current UI state to a single subscriber, while SharedFlow is for broadcasting events to multiple collectors. Choosing between them depends on whether you need state retention or event distribution in your asynchronous data streams.

How do I ensure lifecycle-safe collection of Kotlin Flows in Android?

Lifecycle-safe Flow collection in Android ensures streams are only collected when the UI is active. This prevents memory leaks and crashes by scoping coroutine collection to valid lifecycle states, stopping emissions when the screen is not visible.

What is the best way to test Kotlin Flows with Turbine?

Testing Kotlin Flows with Turbine allows you to validate asynchronous data stream emissions, operator chains, and error handling. It provides a virtual time controller to assert emission sequences and verify reactive programming logic without actual delays.

How do I convert callback-based APIs to Kotlin Flows?

Callback bridging converts callback-based APIs into Kotlin Flows by using suspendCancellableCoroutine or callbackFlow. This allows you to wrap existing asynchronous network sources and emit real-time data updates through standard Flow operators.

Can I use Kotlin Coroutines Flows for state management in KMP projects?

Kotlin Coroutines Flows are fully compatible with Kotlin Multiplatform (KMP) projects for state management. They provide KMP-specific patterns for asynchronous data streams that work across multiple platforms while maintaining consistent reactive programming behavior.

When should I migrate from Kotlin Channels to Flows for asynchronous programming?

Migrating from Kotlin Channels to Flows is recommended when you need state management and continuous data streams rather than single element passing. Flows offer better operator chains and lifecycle-safe collection compared to raw Channel synchronization.