0
0
Android Kotlinmobile~5 mins

SharedFlow for events in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is SharedFlow in Kotlin?
SharedFlow is a hot flow that allows multiple collectors to receive the same emitted values. It is useful for sharing events or data streams across different parts of an app.
Click to reveal answer
intermediate
Why use SharedFlow for events instead of StateFlow?
SharedFlow is better for one-time events because it can replay a configurable number of past events and does not hold a current state like StateFlow. StateFlow always holds the latest value, which is not ideal for events.
Click to reveal answer
beginner
How do you configure a SharedFlow to replay the last event for new subscribers?
You set the replay parameter when creating the SharedFlow. For example, MutableSharedFlow(replay = 1) will replay the last emitted event to new subscribers.
Click to reveal answer
beginner
What does it mean that SharedFlow is a hot flow?
A hot flow means it emits values regardless of whether there are active collectors. Events are produced continuously and shared with all subscribers.
Click to reveal answer
beginner
How can you emit an event using a MutableSharedFlow?
You call the emit() suspend function or tryEmit() function on the MutableSharedFlow instance to send an event to all collectors.
Click to reveal answer
What parameter controls how many past events a SharedFlow replays to new subscribers?
Acapacity
BbufferSize
Creplay
DcacheSize
Which of these is true about SharedFlow?
AIt is a cold flow that starts emitting only when collected
BIt is a hot flow that emits events regardless of collectors
CIt holds a current state like StateFlow
DIt cannot have multiple subscribers
Which function is used to send an event to a MutableSharedFlow?
Aemit()
Bcollect()
Csubscribe()
Dlaunch()
Why is SharedFlow preferred over StateFlow for one-time events?
ASharedFlow holds the latest state
BStateFlow replays all past events
CStateFlow is not observable
DSharedFlow can replay a limited number of events without holding state
What happens if you collect a SharedFlow after some events have already been emitted and replay is set to 0?
AYou receive no past events, only new ones
BYou receive all past events
CYou receive only the latest event
DThe flow throws an error
Explain how SharedFlow works for event handling in Android Kotlin apps.
Think about how events are shared and replayed to subscribers.
You got /5 concepts.
    Describe the difference between SharedFlow and StateFlow and when to use each.
    Consider how each flow handles data and events.
    You got /5 concepts.