Member-only story
🚀 Android Interview Questions Series Part 8: 2025🚀
Ques 1: What is LiveData, and how is it different from StateFlow?
Answer:
LiveData:
1. Designed to work with Android’s View components.
2. It is Lifecycle-aware, meaning it automatically cleans up when an activity is destroyed.
StateFlow:
1. Jetpack works better with Compose and coroutines.
2. It always stores the latest value and gives the last value even after a subscription.
Difference between the two:
1. LiveData is lifecycle-aware, StateFlow is not.
2. StateFlow retains the latest value, not LiveData.
Ques 2. Explain the difference betweenlaunch
, async
, and runBlocking
in Kotlin coroutines.
Answer:launch
(Fire & Forget) 🔥
1. It starts a background task and does not return results.
2. It is non-blocking, meaning it allows the rest of the code to run.
✅ Use when: You do not want the result, just run the task.
🔹Example:
GlobalScope.launch {
println("Launch: Background task running...")
}