0% found this document useful (0 votes)
90 views120 pages

Jetpack Compose Interview Questions Guide

The document provides an in-depth overview of Jetpack Compose, a modern declarative UI toolkit for Android that replaces XML layouts. It covers key concepts such as @Composable functions, recomposition, state management, and the slot table, emphasizing the efficiency and productivity improvements offered by Compose. Additionally, it discusses various side-effect APIs and their use cases, highlighting the architecture and internal workings of the toolkit.

Uploaded by

waqascheckiteasy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views120 pages

Jetpack Compose Interview Questions Guide

The document provides an in-depth overview of Jetpack Compose, a modern declarative UI toolkit for Android that replaces XML layouts. It covers key concepts such as @Composable functions, recomposition, state management, and the slot table, emphasizing the efficiency and productivity improvements offered by Compose. Additionally, it discusses various side-effect APIs and their use cases, highlighting the architecture and internal workings of the toolkit.

Uploaded by

waqascheckiteasy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

d

oi
100 Most-Asked Jetpack Compose

n dr
Interview Questions (Deep-Drive

-a
nu
Answers)

ha
ris
/k
1. What is Jetpack Compose? Explain its
/in

architecture and how it works internally.


m
co

Jetpack Compose is Android’s modern declarative UI toolkit built to replace XML-based


layouts. Instead of updating UI manually, you describe the UI, and Compose updates only what
n.

changes.
di
ke
lin

How It Works / Core Architecture


n.

Jetpack Compose runs on five core layers:


//i
s:
tp

① Declarative UI Model
ht

Old XML approach → update UI manually (adapters, listeners, notifyDataSetChanged).​


Compose approach → UI = function of state.

@Composable
fun Greeting(name: String) {
Text("Hello $name")
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
dr
Whenever name changes → Compose recomposes only this part.

n
-a
nu
② Composition

ha
Composition = Tree of UI nodes created from Composable functions.

Column {
ris
/k
Text("Title")
/in
Button(onClick = {}) { Text("Click") }
}
m
co

This tree helps Compose know which UI elements depend on which state.
n.
di
ke

③ Recomposition (MOST IMPORTANT)


lin

Recomposition only redraws the part whose state changed, not the entire screen.
n.

Flow:​
//i

State → Observed → Dirty flag → Only affected Composables re-executed.


s:
tp


Interview hint:​
Recomposition is incremental, targeted, and super lightweight.
ht

④ State & State Hoisting

Compose is state-driven.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
var count by remember { mutableStateOf(0) }

oi
dr
UI automatically updates when count changes.

n
-a
Best practice: Move state upwards (state hoisting) to avoid duplicates and maintain UDF.

nu
ha
⑤ Compose Compiler + Runtime

ris
●​ Compose Compiler Plugin: Converts @Composable into optimized code.​
/k
/in
●​ Compose Runtime: Manages slot table, recomposition, state reads, and skips.​
m
co
n.

Lifecycle in Compose
di

Compose lifecycle equivalents:


ke

Concept Purpose
lin

remember Keep state across recompositions


n.
//i

rememberSaveable Keep state across config changes


s:

LaunchedEffect Run suspend jobs on entering


tp

composition
ht

DisposableEffect Cleanup when leaving composition

Why Compose is Faster?

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ No XML inflation​

oi
✔ Updates only changed UI​
✔ Compiler optimization​

dr
✔ Kotlin-first design

n
-a
nu
Use Cases

ha
●​ Dynamic screens​

●​ Forms​
ris
/k
/in
●​ Material 3 UI​
m

●​ Animation-heavy screens​
co

●​ Lazy lists​
n.
di
ke

Example Implementation
lin

@Composable
n.

fun CounterScreen() {
//i

var count by remember { mutableStateOf(0) }


s:

Column(
tp

horizontalAlignment = [Link],
verticalArrangement = [Link],
ht

) {
Text("Count: $count", fontSize = [Link])
Button(onClick = { count++ }) {
Text("Increase")
}

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
}

n dr
-a
Short Summary (Interview)

nu
Jetpack Compose is a declarative UI toolkit that rebuilds UI on state changes using

ha
composition, recomposition, compiler optimizations, and unidirectional data flow. It eliminates
XML, improves productivity, and delivers highly efficient UI rendering.

ris
/k
/in

2. What is @Composable? How does it


m
co

work internally?
n.

A @Composable function lets you define UI in Kotlin instead of XML.


di
ke
lin

How It Works Internally


n.

@Composable is not just an annotation—​


//i

the Compose compiler transforms it into a special function that:


s:
tp

●​ Emits UI nodes into the composition​


ht

●​ Tracks state reads​

●​ Saves slot table positions​

●​ Allows skipping during recomposition​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
Rules of @Composable

n dr
●​ Should be side-effect free​

-a
nu
●​ Can only be called from other Composables​

ha
●​ Must be fast & deterministic​

ris
●​ Should not perform long operations​
/k
/in
m

Composition Example
co

@Composable
fun UserCard(name: String) {
n.

Text("User: $name")
di

}
ke
lin

If name changes → only this function recomposes.


n.
//i
s:

Why Important?
tp

Understanding @Composable = understanding Compose architecture deeply.


ht

Short Summary

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
A Composable defines UI using Kotlin functions. The Compose compiler rewrites them to

oi
manage composition, state tracking, and efficient rendering.

n dr
-a
3. Explain Recomposition in Jetpack

nu
Compose with internal working.

ha
ris
Recomposition is the process where Compose re-executes specific Composables when state
/k
they read changes.
/in
m

How It Works Internally


co

1.​ During composition → state reads registered​


n.
di

2.​ When state changes → composer marks nodes as dirty​


ke

3.​ Only those nodes re-run​


lin

4.​ Skipped nodes reused from slot table​


n.
//i

5.​ UI updates incrementally​


s:
tp
ht

Important Points

●​ Not entire screen redraw​

●​ Uses snapshot state system​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Very efficient memory-wise​

oi
●​ Happens asynchronously​

n dr
-a
nu
Example

ha
var name by remember { mutableStateOf("John") }

ris
Text("Hello $name") /k
/in

Changing name → only Text recomposes.


m
co
n.

Short Summary
di

Recomposition is targeted UI update triggered by state changes, using slot table & snapshot
ke

system.
lin
n.
//i

4. What is remember and why do we use


s:

it?
tp
ht

remember caches value during recomposition.

var count by remember { mutableStateOf(0) }

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
How It Works

oi
●​ Stores value in Composition slot table​

n dr
●​ Reused during recomposition​

-a
nu
●​ Lost when Composable leaves composition​

ha
Use Cases
ris
/k
/in
●​ UI local state​
m

●​ Animation state​
co

●​ Flag states​
n.
di
ke

Short Summary
lin
n.

remember stores state across recompositions but not across configuration changes.
//i
s:
tp

5. remember vs rememberSaveable
ht

Feature remember rememberSaveable

Survives recomposition ✔ ✔

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Survives rotation ✘ ✔

oi
dr
Stored in Slot table Bundle/SavedState

n
-a
Example

nu
val name = rememberSaveable { mutableStateOf("") }

ha
ris
Best for forms & inputs.
/k
/in
m

6. Explain State Hoisting in Compose


co

State hoisting = lifting state to parent Composable.


n.
di
ke

Why?
lin

●​ Avoid duplicate states​


n.
//i

●​ Promote unidirectional data flow​


s:

●​ Make Composables reusable​


tp
ht

Pattern

Old:

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Child manages state → not reusable

oi
dr
Hoisted:

n
-a
@Composable

nu
fun Parent() {
var text by remember { mutableStateOf("") }

ha
Child(text) { text = it }
}

ris
/k
/in

7. What is the Slot Table? How does


m
co

Compose use it?


n.
di

The Slot Table is Compose's internal data structure that stores:


ke

●​ Composition tree​
lin

●​ State references​
n.
//i

●​ Remembered values​
s:

●​ Keys​
tp
ht

●​ Layout nodes​

It helps Compose know:

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ What changed​

oi
✔ What to skip​
✔ What to reuse

n dr
-a
Short Summary

nu
ha
Slot table = Compose’s internal database for UI rendering.

ris
/k
8. Explain Unidirectional Data Flow (UDF)
/in
m

in Compose
co

UDF =​
n.

State flows down → UI​


di

Events flow up → ViewModel


ke
lin

Why Important?
n.
//i

●​ Highly predictable​
s:

●​ Debug-friendly​
tp
ht

●​ Avoids inconsistent UI​

Structure

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
state → UI → event → ViewModel → new state → UI

oi
n dr
-a
9. What is a Modifier? Explain its

nu
architecture.

ha
ris
Modifiers decorate or enhance UI behavior.
/k
/in

Modifier Chain Architecture


m

Modifiers are applied sequentially:


co

Modifier
n.

.padding([Link])
di

.background([Link])
ke

.clickable { }
lin
n.

Internally:
//i

●​ Each modifier creates a node​


s:
tp

●​ Nodes applied to layout/draw/interaction chain​


ht

Types

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Layout​

oi
●​ Draw​

n dr
●​ Gesture​

-a
nu
●​ Animation​

ha
●​ Semantics​

ris
/k
/in

10. What is a Side Effect in Compose?


m

Explain all side-effect APIs.


co
n.

Side effects = operations that should not run during composition.


di
ke
lin

Main Side-Effect APIs


n.

✔ LaunchedEffect
//i

Runs suspend tasks on entering composition.


s:
tp

✔ DisposableEffect
ht

Has cleanup logic.

✔ SideEffect

Called after recomposition.

✔ rememberCoroutineScope
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Launch externally controlled coroutines.

oi
✔ produceState

n dr
Convert async data → State.

-a
nu
Short Summary

ha
Side effects allow safe execution of external tasks like coroutines, observers, listeners.

ris
/k
/in

11. What is LaunchedEffect? Explain when


m
co

and why it is used.


n.
di

LaunchedEffect is a side-effect Composable used to run suspend functions or coroutines


ke

when a key enters the composition.


lin

It guarantees:
n.

●​ Runs only once per key​


//i

●​ Cancels when the key changes​


s:
tp

●​ Cancels when the Composable leaves the composition​


ht

How It Works / Internal Architecture


LaunchedEffect uses:
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Composition lifecycle​

oi
●​ CoroutineScope tied to the Composable​

n dr
●​ Snapshot state observation​

-a
nu
Flow:

ha
1.​ When Composable enters composition → LaunchedEffect launches a coroutine​

2.​ Coroutine tied to the Composable’s lifecycle​


ris
/k
/in
3.​ If key changes → previous coroutine canceled → new launched​
m

4.​ If Composable removed → coroutine automatically canceled​


co
n.
di

Use Cases
ke
lin

✔ Fetch API data once​


✔ Trigger animations​
n.

✔ One-time events (toast, snackbar)​


//i

✔ Listening to Flows/StateFlow
s:
tp
ht

Example
@Composable
fun UserScreen(viewModel: UserViewModel) {
LaunchedEffect(Unit) {
[Link]()
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
}

n dr
This ensures data loads only once when screen renders.

-a
nu
ha
Short Summary

ris
LaunchedEffect runs suspend tasks safely within a Composable lifecycle, automatically
/k
canceling when the UI changes.
/in
m
co

12. What is DisposableEffect? Explain with


n.

detailed use cases.


di
ke

DisposableEffect is a side-effect handler that executes cleanup logic when a Composable


lin

leaves the composition.


n.
//i
s:

How It Works / Internal Architecture


tp

DisposableEffect registers cleanup tasks using:


ht

●​ onDispose { … }​

●​ Composition lifecycle​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Snapshot observer teardown​

oi
n dr
-a
Flow:

nu
1.​ When key enters → setup block runs​

ha
2.​ When key changes or Composable removed → onDispose executes​

3.​ Perfect for resources that require cleanup​


ris
/k
/in
m
co

Use Cases
n.

✔ Registering/unregistering BroadcastReceivers​
di

✔ Adding/removing listeners​
ke

✔ Sensor callbacks​
✔ Location providers​
lin

✔ Media player cleanup​


✔ Observers cleanup
n.
//i
s:
tp

Example
ht

DisposableEffect(Unit) {
val receiver = registerReceiver()
onDispose {
unregisterReceiver(receiver)
}
}
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
Short Summary

n
-a
DisposableEffect is used for setup + cleanup around external resources tied to lifecycle.

nu
ha
13. Explain produceState in Jetpack
ris
/k
Compose.
/in
m

produceState converts external asynchronous data into Compose State.


co
n.
di

How It Works
ke
lin

●​ Internally creates a coroutine​


n.

●​ Produces state using value = …​


//i

●​ Emits initial & updated values​


s:
tp

●​ Survives recomposition​
ht

●​ Cancels on removal​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Use Cases

oi
dr
✔ Convert Flow to State​
✔ Convert callbacks to State​

n
✔ API calls returning multiple updates​

-a
✔ Realtime updates (socket, sensors)

nu
ha
Example
@Composable
ris
/k
fun UserData(userId: String): State<User> {
/in

return produceState(initialValue = [Link], userId) {


m

value = [Link](userId)
co

}
}
n.
di
ke

Short Summary
lin
n.

produceState bridges asynchronous data → Compose UI by emitting State from coroutines.


//i
s:
tp

14. What is derivedStateOf and why is it


ht

important?
derivedStateOf optimizes expensive UI calculations by memoizing results.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
How It Works

n
-a
●​ Tracks dependencies​

nu
●​ Recomputes only when dependency changes​

ha
●​ Prevents useless recompositions​

●​ Works like computed in Vue or memo in React​


ris
/k
/in
m
co

Use Case Example


n.

val filteredList by derivedStateOf {


[Link] { [Link] }
di

}
ke
lin

This recalculates only when users changes.


n.
//i
s:

Why Important?
tp
ht

✔ Improves performance​
✔ Reduces recompositions​
✔ Avoids heavy calculations running repeatedly

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Short Summary

oi
dr
derivedStateOf creates optimized, memoized state for expensive calculations inside

n
Compose.

-a
nu
15. Explain Snapshot System in Jetpack

ha
Compose.
ris
/k
The Snapshot system is Compose’s reactive state management engine.
/in
m
co

How It Works
n.

●​ Tracks state read inside Composables​


di
ke

●​ On state write → creates snapshot​


lin

●​ Marks affected components as dirty​


n.

●​ Initiates recomposition​
//i
s:
tp

Key Principles:
ht

1.​ Transactional → Changes applied atomically​

2.​ Observable → Compose watches state reads​

3.​ Thread-safe → Supports multi-threading​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
Use Cases

n
-a
✔ Compose state (mutableStateOf)​
✔ remember​

nu
✔ State in ViewModel​

ha
✔ Animation states

ris
/k
Short Summary
/in

Snapshot system is the engine behind Compose's reactive UI updates, detecting state changes
m

and triggering recompositions.


co
n.
di

16. What is CompositionLocal? Explain


ke

internal working.
lin
n.

CompositionLocal provides dependency injection-like values down the composition tree.


//i
s:
tp
ht

How It Works
●​ Injects values without passing them through every parameter​

●​ Works like React context or Flutter's inherited widget​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Uses snapshot reads for updates​

oi
●​ Recomposition triggers where value is used​

n dr
-a
nu
Use Cases

ha
✔ Current Theme​

ris
✔ Current App Locale​ /k
✔ Current User​
✔ Window Insets​
/in
✔ Spacing / Dimensions
m
co
n.

Example
di

val LocalSpacing = compositionLocalOf { [Link] }


ke

CompositionLocalProvider(LocalSpacing provides [Link]) {


lin

Text("Hello", modifier = [Link]([Link]))


n.

}
//i
s:
tp

Short Summary
ht

CompositionLocal allows passing data implicitly down the UI tree without prop-drilling.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
17. Explain Modifier internals in Jetpack

oi
dr
Compose.

n
-a
A Modifier is a declarative way to modify:

nu
●​ layout​

ha
●​ drawing​

●​ gesture​
ris
/k
/in
●​ semantics​
m
co
n.

Modifier Chain Architecture


di
ke

Each modifier generates a node in a chain:


lin

[Link]() → LayoutNode
[Link]() → DrawNode
n.

[Link]() → InteractionNode
//i
s:

Compose applies nodes in order:


tp
ht

1.​ Layout​

2.​ Draw​

3.​ Input​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
4.​ Semantics​

oi
n dr
-a
Why Important?

nu
✔ Predictable behavior​

ha
✔ Easy customization​
✔ Extensible UI pipeline

ris
/k
/in

Short Summary
m
co

Modifier is a chain of behavior nodes that affect layout, drawing, and interaction in Compose.
n.
di
ke

18. What are Keys in LazyColumn and why


lin

do we need them?
n.
//i

Keys uniquely identify list items in LazyColumn.


s:
tp
ht

Why Needed?
Without keys:

●​ Scroll jumps​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Wrong item reused​

oi
●​ Incorrect animations​

n dr
●​ State misplaced​

-a
nu
ha
Example
items(users, key = { [Link] }) {
ris
/k
UserRow(it)
/in
}
m
co
n.

Internal Behavior
di

●​ Compose stores each item’s identity​


ke
lin

●​ If list order changes → Compose matches items by key​


n.

●​ Prevent unnecessary recomposition​


//i
s:
tp
ht

Short Summary
Keys stabilize list items to prevent UI inconsistencies during recomposition or data updates.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
19. What is rememberCoroutineScope?

oi
dr
How is it different from LaunchedEffect?

n
-a
rememberCoroutineScope

nu
Creates a coroutine scope manual control inside Composables.

ha
LaunchedEffect

Runs automatically when entering composition.


ris
/k
/in
m

Difference Table
co

Feature rememberCoroutineScope LaunchedEffect


n.
di

When runs When manually launched Automatically


ke

Lifecycle tied to Composable Composable


lin

Cancellation Manual Automatic


n.

Use case Snackbar, events API calls,


//i

animations
s:
tp
ht

Example
val scope = rememberCoroutineScope()
Button(onClick = {
[Link] { [Link]("Hello") }
}) {

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Text("Show Snackbar")

oi
}

n dr
-a
Short Summary

nu
ha
rememberCoroutineScope gives a lifecycle-aware coroutine scope for manual launches, unlike
automatic LaunchedEffect.

ris
/k
/in

20. How do animations work in Jetpack


m

Compose? Explain core concepts.


co
n.

Compose animations are state-driven and powered by:


di

●​ Physics-based animations​
ke

●​ Tween animations​
lin
n.

●​ Keyframes​
//i

●​ Infinite transitions​
s:
tp
ht

Core Concepts
① animate*AsState

Simple state-driven animation.


Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
② updateTransition

oi
Group multiple animations.

n dr
③ Animatable

-a
nu
Low-level controllable animations.

ha
④ InfiniteTransition

ris
Loops forever.
/k
⑤ AnimationSpec
/in

Defines duration, easing, delay.


m
co
n.

Internal Architecture
di
ke

●​ Uses choreographer for 60fps frames​


lin

●​ Re-runs animation block on each frame​


n.

●​ Updates state → triggers recomposition​


//i
s:

●​ Renderer applies animated UI​


tp
ht

Example
val alpha by animateFloatAsState(
targetValue = if (visible) 1f else 0f

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
)

oi
n dr
Short Summary

-a
nu
Animations in Compose are based on observable state changes and render with

ha
frame-by-frame recompositions.

ris
/k
21. What is Recomposition in Jetpack Compose? How
/in

does it know what to recompose?


m
co

Recomposition = the process where Compose re-executes only those @Composable functions
whose inputs (state) have changed.
n.

How Recomposition Works Internally


di
ke

Compose tracks:
lin

●​ The previous state values​


n.

●​ The current state values​


//i
s:

●​ Which Composables read which state​


tp
ht

When a state changes (mutableStateOf), Compose marks those composables as invalid →


schedules recomposition.

Key Points

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Recomposition is incremental, not a full redraw.​

oi
●​ Compose uses a SlotTable to track UI structure & efficiently update nodes.​

n dr
●​ Only functions reading changed state re-run.​

-a
nu
●​ Order matters. If Composable function order changes → new composition tree.​

ha
Example

ris
var name by remember { mutableStateOf("John") } /k
/in
Text("Hello $name")
m

Changing name → only this Text recomposes.


co
n.

Interview Tip:​
Recomposition is not triggered when you call a composable—it’s triggered when
di

state changes.
ke
lin
n.

22. What is the Slot Table in Jetpack Compose?


//i

The SlotTable is the internal data structure that stores:


s:
tp

●​ Composition tree​
ht

●​ State "slots"​

●​ Remembered values​

●​ Node relationships​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Think of it as Compose’s virtual DOM.

oi
Responsibilities

n dr
●​ Tracks what was composed last time​

-a
nu
●​ Decides what needs updating​

ha
●​ Avoids recreating UI elements unnecessarily​

ris
●​ Optimizes diffing​
/k
/in
Why Important?
m

Without SlotTable, Compose would recompose entire UI, making it slow.


co

Interview Tip:​
n.

SlotTable = Compose's engine to match old & new UI efficiently.


di
ke
lin

23. What is remember and how does it store values?


n.

remember { } stores a value in the SlotTable during composition.


//i
s:

Key Properties
tp

●​ Persists across recompositions​


ht

●​ Resets when the composable leaves composition​

●​ Does NOT survive:​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
○​ configuration change​

oi
○​ process death​

n dr
-a
Example:

nu
val count = remember { mutableStateOf(0) }

ha
ris
Internals
/k
●​ Stored in composition slots​
/in

●​ Returned instantly on recomposition​


m
co

●​ Not executed again unless needed (skipped due to optimization)​


n.
di
ke

24. Difference between remember and rememberSaveable


lin

Aspect remember rememberSaveable


n.

Lives across recomposition ✅ ✅


//i

❌ ✅
s:

Lives across configuration


tp

change


ht

Survives process death Typically yes

Storage SlotTable Bundle +


SavedStateHandle

Example:

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
rememberSaveable { mutableStateOf(0) }

oi
dr
Use rememberSaveable for:

n
-a
●​ Input fields​

nu
●​ Counters​

ha
●​ UI selections​

●​ Navigation state​
ris
/k
/in
m
co

25. What is SideEffect in Compose? When do you use it?


n.

SideEffect runs after every successful recomposition.


di
ke

Example
SideEffect {
lin

println("Recomposed")
n.

}
//i
s:

Use Cases
tp
ht

●​ Logging recompositions​

●​ Notifying external systems​

●​ Synchronizing external states​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Important

oi
●​ Runs on main thread​

n dr
●​ Runs every recomposition, so use carefully​

-a
nu
ha
26. What is DisposableEffect? How does cleanup work?

ris
/k
DisposableEffect is used to run side-effects tied to the lifecycle of a composable.
/in
Example:
m

DisposableEffect(Unit) {
co

startLocationUpdates()
n.

onDispose {
di

stopLocationUpdates()
ke

}
lin

}
n.
//i

Triggered When:
s:

●​ Keys change​
tp
ht

●​ Composable leaves composition​

Use Cases

●​ Location listener​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Broadcast receivers​

oi
●​ Lifecycle observers​

n dr
●​ Sensors​

-a
nu
●​ Callbacks cleanup​

ha
27. What is LaunchedEffect? Why is it needed? ris
/k
/in

LaunchedEffect launches a coroutine tied to the composable lifecycle.


m

Example:
co

LaunchedEffect(Unit) {
n.

loadUserData()
di

}
ke
lin

Features
n.

●​ Runs only when key changes​


//i
s:

●​ Gets canceled when composable leaves the composition​


tp

●​ Useful for:​
ht

○​ API calls​

○​ Animations​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
○​ One-time tasks​

oi
dr
Internally uses rememberCoroutineScope() + Composition lifecycle.

n
-a
nu
28. What is the difference between DerivedStateOf and

ha
SnapshotState?

ris
Feature SnapshotState
/k DerivedStateOf

Stores actual state Yes No (computed)


/in

Used for raw data Yes No


m
co

Used for computed memoized values No Yes


n.

Recomputes only when dependencies No Yes


change
di
ke

Example:
lin

val filteredList by derivedStateOf { [Link] { [Link] } }


n.
//i

Why use it?


s:
tp

●​ Avoid recomputing heavy operations​


ht

●​ Optimize recomposition​

●​ Makes computed state stable​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
29. What is rememberUpdatedState?

oi
dr
Used to capture the latest value inside side effects like LaunchedEffect.

n
Problem:​

-a
LaunchedEffect captures old values due to coroutine scope.

nu
Solution:

ha
val latestCallback by rememberUpdatedState(onClick)

ris
/k
Fixes stale lambda issues.
/in
m
co

30. What are Keys in Compose? Why do we need key()


n.

function?
di

Compose may reuse nodes during recomposition.​


ke

When lists reorder → wrong items may get reused.


lin

key() provides identity.


n.

Example:
//i
s:

key([Link]) {
tp

UserRow(user)
}
ht

Required When:

●​ List items reorder​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Items insert/delete​

oi
●​ Animation-based UI​

n dr
●​ LazyColumn dynamic data​

-a
nu
How it works internally

ha
●​ Compose stores key → slot mapping​

●​ When recomposing, it matches based on key​


ris
/k
/in
●​ Ensures correct reuse of nodes​
m
co
n.

31. What is CompositionLocal? How does


di
ke

it replace Context in Compose?


lin

CompositionLocal is a way to pass data down the composition tree without explicitly
n.

passing it through every parameter.


//i
s:

Example
tp

val LocalUser = compositionLocalOf<String> { error("No user found") }


ht

CompositionLocalProvider(LocalUser provides "Krishanu") {


ProfileScreen()
}

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Inside ProfileScreen():

oi
val user = [Link]

n dr
-a
Use Cases

nu
●​ Themes (colors, typography)​

ha
●​ Locale settings​

●​ User preferences​
ris
/k
/in
●​ Window size, screen configs​
m

●​ Global app-level states​


co
n.

How It Works Internally


di

●​ The value is stored in the Composition tree​


ke
lin

●​ Any composable below the provider can read it​


n.

●​ Recomposition happens only to consumers when the value changes​


//i
s:

Interview Tip: Replace Context-dependent logic like retrieving resources with


tp

CompositionLocal where possible.


ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
32. What is the difference between

oi
dr
compositionLocalOf and

n
staticCompositionLocalOf?

-a
nu
Feature compositionLocalO staticCompositionLocalO

ha
f f

ris
Recomposition triggered Yes Usually no

Used for dynamic values Yes


/k No
/in
Needed when values may change Yes No
often
m

❌ ✔️
co

Better performance?
n.

Example
di
ke

Use compositionLocalOf for:


lin

●​ User session​
n.

●​ Theme modes​
//i
s:

Use staticCompositionLocalOf for:


tp
ht

●​ Colors​

●​ Typography​

●​ Fixed config​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Why?

oi
staticCompositionLocalOf allows Compose to skip more recompositions → better

dr
performance.

n
-a
nu
33. What is Snapshot System in Jetpack

ha
ris
Compose? /k
/in
Compose uses a Snapshot system to track mutable state changes.
m

Key Concepts
co

1.​ SnapshotState — wraps mutable data (mutableStateOf)​


n.

2.​ Readable snapshot — reading state​


di
ke

3.​ Mutable snapshot — changing state​


lin

4.​ Applier — applies state changes to UI tree​


n.
//i

Snapshot Responsibilities
s:
tp

●​ Detect state changes​


ht

●​ Schedule recompositions​

●​ Ensure thread safety​

●​ Avoid inconsistent UI states​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Why it matters?

oi
Compose updates UI predictably even when multiple states update in parallel.

n dr
-a
nu
34. Explain Stability in Jetpack Compose.

ha
Why “stable” objects matter?
ris
/k
Compose uses stability to decide whether a Composable needs recomposition.
/in

A “Stable” object guarantees:


m

●​ It won't change internally without Compose knowing​


co
n.

●​ Equality checks work predictably​


di

●​ Its fields are stable or immutable​


ke
lin

When an object is stable:


n.

Compose skips recomposition when it is passed as a parameter → performance boost.


//i
s:

How to make objects stable?


tp

1.​ Make data classes immutable​


ht

2.​ Use @Immutable​

3.​ Use @Stable when you provide custom guarantees​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Example:

oi
@Immutable

dr
data class User(val name: String, val age: Int)

n
-a
nu
Interview Tip

ha
Understanding stability shows deep Compose performance knowledge.

ris
/k
/in
35. What is the difference between
m

@Stable and @Immutable?


co
n.

Feature @Stable @Immutable

❌ (can mutate safely) ✔️ (fully immutable)


di

Object should not mutate

❌ ✔️
ke

Compose assumes all fields


lin

stable?
n.

Performance optimization level Medium High


//i
s:

Example Use
tp

@Stable — Mutable objects with controlled mutation​


ht

@Immutable — Immutable data classes

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
36. How do animations work internally in

oi
dr
Jetpack Compose?

n
-a
Compose animations are state-driven:

nu
1.​ You change animation state​

ha
2.​ Compose runs animation clock​

3.​ Recomposition happens many times per second​


ris
/k
/in
4.​ UI updates smoothly​
m
co

Types of Animations
n.

●​ animate*AsState → simple values​


di

●​ updateTransition → multi-value transitions​


ke
lin

●​ AnimatedVisibility → layout-based animations​


n.

●​ Animatable → manual animation control​


//i
s:

Example
tp
ht

val alpha by animateFloatAsState(


targetValue = if (visible) 1f else 0f
)

Engine

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Compose uses:

oi
●​ Choreographer (Android)​

n dr
●​ Coroutines​

-a
●​ Frame clock​

nu
ha
●​ Physics-based animations (spring, decay)​

ris
/k
/in

37. What are keys in LazyColumn? Why


m

are they important?


co
n.

In LazyColumn, keys help Compose identify list items uniquely.


di
ke

Example:
lin

items(users, key = { [Link] }) { user ->


UserItem(user)
n.

}
//i
s:

Why required?
tp
ht

Without keys:

●​ Compose reuses wrong item slots​

●​ UI flickers​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Animation bugs​

oi
●​ Wrong states restored inside rows​

n dr
●​ Scrolling may break​

-a
nu
Internally

ha
●​ Compose maps key → slot​

ris
●​ Reuses or removes nodes during recomposition based on key matching​
/k
/in
m
co

38. How does LazyColumn work


n.

internally?
di
ke

LazyColumn only composes items that are visible.


lin

Compositional Steps:
n.
//i

1.​ Measures viewport​


s:
tp

2.​ Determines visible indices​


ht

3.​ Composes only visible items​

4.​ Recycles & reuses item slots​

5.​ Uses LazyListState to track scroll position​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
6.​ Offscreen items are disposed automatically​

oi
dr
Benefits

n
-a
●​ Efficient memory usage​

nu
●​ Smooth scrolling​

ha
●​ State preservation inside each row​

ris
/k
/in
m

39. What is the difference between


co

[Link] vs Box with


n.

background?
di
ke

[Link]
lin
n.

●​ Only draws background behind content​


//i

●​ Does not add padding​


s:
tp

●​ Does not affect layout size​


ht

Example:

Text("Hello", [Link]([Link]))

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Box with background

oi
Box([Link]().background([Link])) {

dr
Text("Hello")

n
}

-a
nu
●​ Box creates a layout node​

ha
●​ Can contain multiple children​

●​ Can modify size, alignment, padding​


ris
/k
/in

Interview Tip
m

[Link] is lightweight compared to additional composable nodes.


co
n.
di
ke

40. Explain the Compose Compiler Plugin.


lin

Why do we need it?


n.
//i

The Compose Compiler Plugin transforms @Composable functions into optimized code.
s:

Responsibilities:
tp
ht

●​ Turns composables into a state machine​

●​ Handles SlotTable management​

●​ Tracks state reads​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Inserts recomposition logic​

oi
●​ Eliminates unused parameters​

n dr
●​ Rewrites lambdas​

-a
nu
●​ Performs stability inference​

ha
Why Needed?

●​ Kotlin alone cannot handle composition tree​


ris
/k
/in
●​ Avoids reflection​
m

●​ Extremely optimized for performance​


co
n.

Example:​
A simple Text("Hi") is transformed into hundreds of lines of optimized machine-level
di

operations.
ke
lin
n.
//i

41. What is DerivedStateOf and why is it


s:
tp

used?
ht

derivedStateOf creates a memoized value that recalculates only when its dependencies
change.

Why We Need It

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Compose recomposes UI based on state changes.​

oi
But sometimes you derive another value from a state:

dr
val isValid = [Link]() && age > 0

n
-a
This may cause unnecessary recompositions.

nu
ha
Solution

ris
Use derivedStateOf:
/k
val isValid by derivedStateOf {
/in
[Link]() && age > 0
}
m
co

Benefits
n.
di

●​ Reduces recomposition​
ke

●​ Optimizes performance​
lin

●​ Works well in LazyColumn / heavy UI calculations​


n.
//i
s:

Use Cases
tp

●​ Filtering lists​
ht

●​ Validation​

●​ Derived UI states​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
42. What is snapshotFlow? Explain with a

oi
dr
deep example.

n
-a
snapshotFlow converts Compose state into a Kotlin Flow.

nu
Example:

ha
val scrollState = rememberLazyListState()

LaunchedEffect(Unit) {
ris
/k
snapshotFlow { [Link] }
/in

.collect { index ->


m

println("Visible index changed: $index")


co

}
}
n.
di

Why This Is Useful


ke
lin

●​ Compose state → Flow → collects in coroutine​


n.

●​ No need for LiveData or observers​


//i

●​ Efficient + lifecycle-aware​
s:
tp
ht

Internally

●​ Takes snapshot reads​

●​ Emits only when the state changes​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Batch updates to avoid rapid unnecessary emissions​

oi
n dr
-a
43. Explain the difference between

nu
remember vs rememberSaveable.

ha
Feature remember
ris rememberSaveable
/k
Survives recomposition ✔️ ✔️
/in

❌ ✔️
m

Survives configuration changes


(rotation)
co

Survives process death ❌ ❌ (partially, depending on


n.

saver)
di

Stored in Composition Bundle / SavedStateHandle


ke

memory
lin

Example:
n.

var name by remember { mutableStateOf("") }


//i
s:
tp

Rotate screen → lost.


ht

var name by rememberSaveable { mutableStateOf("") }

Rotate screen → preserved.

Use Cases
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Form fields​

oi
●​ Temporary screen data​

n dr
-a
nu
44. What is LaunchedEffect? How does

ha
ris
it handle lifecycle? /k
/in
LaunchedEffect runs suspend functions inside a composable when a key changes.
m

Example
co

LaunchedEffect(userId) {
n.

[Link](userId)
}
di
ke

Lifecycle Rules
lin
n.

●​ Runs once when key enters composition​


//i

●​ Cancels when key changes​


s:
tp

●​ Cancels when Composable leaves composition​


ht

Internally:

●​ Uses CoroutineScope tied to the composable​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Cancels using structured concurrency​

oi
dr
Use Cases

n
-a
●​ API calls​

nu
●​ Animations​

ha
●​ State initialization​

ris
/k
/in
m

45. What is SideEffect in Compose?


co

When should we use it?


n.
di

SideEffect runs after every successful recomposition.


ke
lin

Example:
SideEffect {
n.

[Link]("Home")
//i

}
s:
tp

Purpose
ht

Used when you must interact with non-Compose world:

●​ Logging​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Firebase​

oi
●​ Analytics​

n dr
●​ Updating external variables​

-a
nu
Internally

ha
Runs after UI is applied → ensures state is stable.

Interview Tip
ris
/k
/in
Use SideEffect only for tiny operations.​
For long-running tasks → use LaunchedEffect.
m
co
n.

46. What is DisposableEffect? Explain


di
ke

a real-life scenario.
lin
n.

Used to perform actions when a composable enters or leaves the composition.


//i

Example:
s:
tp

DisposableEffect(Unit) {
[Link]()
ht

onDispose {
[Link]()
}
}

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
Use Cases

n dr
●​ Observers​

-a
nu
●​ Listeners​

ha
●​ Broadcast receivers​

ris
●​ Sensor APIs​
/k
/in
Internally
m

●​ Tied to Composition lifecycle​


co

●​ Cleans up automatically​
n.
di
ke
lin

47. What is “SlotTable” in Jetpack


n.

Compose?
//i
s:
tp

SlotTable is the main data structure that stores the Composition tree.
ht

Responsibilities

●​ Maps composables → UI nodes​

●​ Tracks state keys​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Maintains remember values​

oi
●​ Optimizes recomposition​

n dr
-a
Internal Working

nu
When a composable runs:

ha
●​ SlotTable allocates "slots"​

●​ Slots store state, references, parameters​


ris
/k
/in
●​ Recomposition updates only necessary slots​
m

This is the secret behind Compose performance.


co
n.
di

48. Explain Recomposer in Jetpack


ke
lin

Compose.
n.
//i

Recomposer = Brain of Compose.


s:

Responsibilities
tp
ht

●​ Listens for state changes​

●​ Schedules recomposition​

●​ Manages frames​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Coordinates UI updates​

oi
●​ Ensures thread safety​

n dr
-a
Life Cycle

nu
1.​ State changes​

ha
2.​ Composer notifies Recomposer​

3.​ Recomposer batches updates​


ris
/k
/in
4.​ UI updated efficiently​
m
co

Interview Tip
n.

If you understand Recomposer → you understand Compose’s core engine.


di
ke
lin

49. What is a “slot”? How does Compose


n.

use slots?
//i
s:
tp

A slot is a storage cell inside SlotTable.


ht

Slots store:

●​ Remembered values​

●​ Keys​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Params​

oi
●​ Skips flags​

n dr
●​ UI node references​

-a
nu
Why Slots?

ha
To:

●​ Skip recompositions​
ris
/k
/in
●​ Track which Composable produced which UI subtree​
m

●​ Restore state automatically​


co
n.

Slots give Compose its incremental update ability.


di
ke
lin

50. Explain the difference between


n.

“Skipping” vs “Recomposing” in
//i
s:

Compose.
tp
ht

Recomposing

●​ Composable function is re-executed​

●​ UI is remeasured and redrawn​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Happens when state changes​

oi
dr
Skipping

n
-a
●​ Compose reuses previously generated UI​

nu
●​ Happens when params are stable​

ha
●​ Zero recomposition cost → fast​

ris
/k
Example:
/in

@Composable
m

fun Title(text: String) { Text(text) }


co
n.

If text doesn't change → Compose skips.


di

Key Mechanism
ke
lin

Skips rely on:


n.

●​ Stability inference​
//i

●​ SlotTable state​
s:
tp

●​ Keys​
ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
51. Explain “Recomposition Scope” in

oi
dr
Jetpack Compose.

n
-a
A recomposition scope defines the region of UI that will recompose when a state read inside

nu
that scope changes.

ha
How It Works

ris
If a Composable reads a state:
/k
@Composable
/in
fun Counter() {
val count by remember { mutableStateOf(0) }
m

Text("Count: $count")
co

}
n.
di

→ Only this Text recomposes when count changes.


ke

Important Points
lin
n.

●​ A scope is created for each @Composable call​


//i

●​ Recomposition boundaries are automatically decided​


s:
tp

●​ Only Composables that read the changed state recompose​


ht

●​ Child and parent scopes are independent​

Why It Matters

Understanding scope helps you optimize performance by minimizing recomposition areas.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
52. What causes unnecessary

n
-a
recompositions? How to avoid them?

nu
ha
Causes

ris
1.​ Passing non-stable objects​
/k
2.​ Creating objects inside Composables​
/in

3.​ Using remember incorrectly​


m
co

4.​ Not using key in lists​


n.

5.​ Updating state excessively​


di

6.​ Using lambdas without remember​


ke
lin

Avoid with:
n.
//i

✔ Use @Immutable or @Stable​


s:

✔ Use remember for objects​


tp

✔ Hoist state​
✔ Avoid creating new lists/maps in Composable
ht

Example BAD:

@Composable
fun Screen() {
val list = listOf(1, 2, 3) // new instance every recomposition

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
dr
FIX:

n
-a
@Composable

nu
fun Screen() {
val list = remember { listOf(1, 2, 3) }

ha
}

ris
/k
/in

53. What is rememberUpdatedState?


m

Why is it important?
co
n.

Used to keep the latest value inside long-running side effects.


di
ke

Problem Example (Wrong)


LaunchedEffect(Unit) {
lin

delay(1000)
n.

onClick() // might use old lambda reference


//i

}
s:
tp

Solution
ht

val updatedOnClick by rememberUpdatedState(onClick)

LaunchedEffect(Unit) {
delay(1000)
updatedOnClick() // always latest

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
dr
Use Cases

n
-a
●​ Callbacks​

nu
●​ Lambdas​

ha
●​ Listeners inside effects​

ris
/k
Why Important?
/in

Without it, your effect might capture old stale values.


m
co
n.

54. Explain how recomposition skipping


di
ke

works internally.
lin
n.

Compose checks:
//i

1.​ Stability of parameters​


s:
tp

2.​ Equality of parameter values​


ht

3.​ SlotTable flags​

If all parameters are stable & unchanged →​


→ Compose skips calling the Composable.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Internally

oi
Each composable call stores:

n dr
●​ Parameter hash​

-a
●​ Stability metadata​

nu
ha
●​ Remembered values​

ris
During next recomposition: /k
●​ Compare with previous slot values​
/in
m

●​ If always equal → skip function body​


co
n.

Result
di

Higher performance → less CPU usage.


ke
lin
n.

55. What is the difference between


//i

“Composition” and “Layout” in Compose?


s:
tp
ht

Concept Composition Layout

Purpose Build the UI tree Measure & place nodes

Happens State or structure Size or constraints change


when changes

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Controlled by Composer, SlotTable LayoutNode & MeasurePolicy

oi
dr
Output Composition tree Pixel positions

n
Simple explanation:

-a
nu
Composition → “What UI to show?”​
Layout → “Where to place it on screen?”

ha
ris
/k
56. How does Modifier chain work
/in
m

internally?
co

Modifiers form a linked list.


n.
di

Each modifier node:


ke

●​ Wraps the underlying node​


lin

●​ Adds behavior (padding, click, background)​


n.
//i

●​ Passes measurement down the chain​


s:
tp

Example:
ht

Modifier
.padding([Link])
.background([Link])
.clickable { }

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Internally:

oi
●​ Top → bottom: layout & drawing​

n dr
●​ Bottom → top: event handling​

-a
nu
Why Important?

ha
Modifier order affects:

ris
●​ Layout​ /k
/in
●​ Drawing​
m

●​ Event priority​
co
n.
di
ke

57. Explain draw order and layout order in


lin

Compose.
n.
//i

Layout order:
s:

●​ Top → bottom (parent → children)​


tp
ht

Draw order:

●​ Children drawn in order of appearance​

●​ Modifiers can override order (e.g., zIndex)​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Example:

oi
Box {

dr
Text("A")

n
Text("B")

-a
}

nu
ha
Draws: A → B​
(B appears on top)

ris
/k
/in

58. How do gestures work in Compose?


m
co

Gesture handling uses pointer input system.


n.

Types:
di
ke

●​ clickable​
lin

●​ pointerInput​
n.
//i

●​ detectTapGestures​
s:
tp

●​ scrollable​
ht

●​ draggable​

Example:
[Link](Unit) {

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
detectTapGestures(

oi
onTap = { println("Tapped!") }

dr
)
}

n
-a
nu
Internally

ha
1.​ Pointer events are intercepted​

ris
2.​ Event passes through modifier layers​ /k
3.​ First handler to consume → stops propagation​
/in
m
co
n.

59. What is SubcomposeLayout? When


di
ke

should you use it?


lin

SubcomposeLayout allows delaying composition until measurement time.


n.
//i

Use Case
s:
tp

●​ When child size depends on sibling measurement​


ht

●​ Complex custom layouts​

●​ Collapsing toolbars​

●​ Tabs + lazy content​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Example

oi
Used in:

n dr
●​ ConstraintLayout​

-a
nu
●​ Scaffold​

ha
●​ LazyColumn​

ris
/k
Why Important?
/in

Normal Compose layout is one directional (parent → children).​


m

SubcomposeLayout allows dynamic, multi-pass measurement.


co
n.
di

60. Explain the 3 phases of Jetpack


ke

Compose UI rendering.
lin
n.

Phase 1 — Composition
//i
s:

●​ Executes Composables​
tp

●​ Builds slot table​


ht

●​ Creates UI tree​

Phase 2 — Layout

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Measures size​

oi
●​ Assigns positions​

n dr
-a
Phase 3 — Drawing

nu
●​ Render pixels onto canvas​

ha
●​ Includes backgrounds, shapes, modifiers​

ris
/k
Why Important?
/in

Knowing phases helps optimize:


m
co

●​ Expensive layouts​
n.

●​ Custom drawing​
di

●​ Skipping unnecessary composition work​


ke
lin
n.
//i
s:

61. What is MutableState? Explain how


tp

Compose tracks & responds to its


ht

changes.
MutableState<T> is an observable state holder that notifies Compose when its value
changes.
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Example

oi
var count by mutableStateOf(0)

n dr
-a
How Compose Tracks Changes

nu
Each MutableState stores:

ha
●​ A value​

ris
●​ A snapshot record​ /k
●​ A list of observers (Recomposer)​
/in
m

When you update:


co

count++
n.
di
ke

Compose:
lin

1.​ Writes new value into snapshot​


n.

2.​ Marks the corresponding slot as “needs recomposition”​


//i

3.​ Schedules recomposer​


s:
tp

4.​ Only recomposes functions that read count​


ht

Why Important?

State drives UI → changes instantly reflect in UI.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
62. Difference Between StateFlow,

oi
dr
LiveData, and MutableState in

n
-a
Compose.

nu
Feature MutableState StateFlow LiveData

ha
Best for UI state Streams + business Legacy

ris
logic /k apps

Thread-safe No Yes Yes


/in

Survives rotation Via ViewModel Yes Yes


m

Compose-friendly ✔️ Best ✔️ Good ✔️ Good


co
n.

Cold/Hot Hot Hot Hot


di

Requires lifecycle? No No Yes


ke

Which should you use?


lin
n.

●​ Inside UI → MutableState​
//i

●​ Business logic (ViewModel) → StateFlow​


s:
tp

●​ Old apps → prefer converting LiveData to StateFlow​


ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
63. Explain produceState with an

oi
dr
example.

n
-a
produceState converts non-UI async operations into Compose state.

nu
Example — Load API Data

ha
@Composable

ris
fun UserScreen(id: Int) {
val user by produceState<User?>(initialValue = null, id) {
/k
value = [Link](id)
/in

}
m
co

Text(user?.name ?: "Loading…")
}
n.
di

Why Useful?
ke
lin

●​ Encapsulates coroutine logic inside composable​


n.

●​ Cancels automatically when key changes​


//i

●​ Re-runs when id changes​


s:
tp
ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
64. What is

oi
dr
rememberCoroutineScope()? How is it

n
-a
different from LaunchedEffect?

nu
ha
rememberCoroutineScope()

ris
Creates a CoroutineScope tied to the composable’s lifecycle.
/k
Example:
/in

val scope = rememberCoroutineScope()


m
co

Button(onClick = {
[Link] { /* long task */ }
n.

}) {
di

Text("Start")
ke

}
lin
n.

Difference vs LaunchedEffect
//i

Feature rememberCoroutineScop LaunchedEffect


s:

❌ ✔️
tp

Runs immediately?
ht

Controlled manually? ✔️ ❌
Good for user ✔️ ❌
actions

Krishanu Nandan
Senior Android Developer
Follow - [Link]
❌ ✔️

d
Good for initial tasks

oi
n dr
-a
65. What is NestedScrollConnection

nu
and when is it used?

ha
ris
Allows two scrollable components to coordinate scroll behavior.
/k
Example Use Cases
/in

●​ Collapsing toolbar​
m
co

●​ Bottom sheet + LazyColumn​


n.

●​ AppBar + List​
di

●​ Custom gestures​
ke
lin

Example Concept
n.

Parent intercepts scroll → child scrolls → parent reacts​


//i

Or vice versa.
s:
tp

It is the engine behind:


ht

●​ Scaffold​

●​ TopAppBar​

●​ LazyColumn nested scroll​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
66. How do keys affect LazyColumn

n
-a
recomposition and state restoration?

nu
ha
Without keys:

ris
Rows get reused randomly​
→ Wrong state inside reused composable
/k
/in
With keys:
m

Slots are tied to each key​


co

→ Stable UI​
→ Correct state
n.
di

Example:
ke

items(list, key = { [Link] }) { user ->


UserItem(user)
lin

}
n.
//i

Internally
s:
tp

Compose stores slotTable entries based on keys.


ht

If a row leaves and re-enters viewport → key allows restoring correct remembered values.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
67. What is View Composition

oi
dr
Strategy? (Important for Android XML +

n
-a
Compose)

nu
When using Compose inside a View (ComposeView), you must choose how/when to dispose

ha
the composition.

Strategies:
ris
/k
/in
1.​ DisposeOnDetachedFromWindow​
m

2.​ DisposeOnLifecycleDestroyed (Recommended)​


co

3.​ DisposeOnViewTreeLifecycleDestroyed​
n.
di

Example:
ke

[Link](
lin

[Link](lifecycle)
)
n.
//i
s:

Why Important?
tp

Avoids:
ht

●​ Memory leaks​

●​ Stale compositions​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Crashes​

oi
n dr
-a
68. Explain interoperability: Using Views

nu
inside Compose.

ha
ris
Use AndroidView. /k
/in
Example:
AndroidView(
m

factory = { context ->


co

TextView(context).apply {
n.

text = "Hello from XML!"


}
di

},
ke

update = { view ->


lin

[Link] = "Updated!"
}
n.

)
//i
s:
tp

Use Cases:
ht

●​ Maps​

●​ Ads​

●​ WebView​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Legacy UI​

oi
dr
Internally

n
-a
Compose measures & lays out the view like a normal composable.

nu
ha
69. Explain interoperability: Using
ris
/k
Compose inside XML.
/in
m

Use ComposeView.
co

XML:
n.

<[Link]
di

android:id="@+id/composeView"
ke

android:layout_width="match_parent"
android:layout_height="wrap_content" />
lin
n.

Activity:
//i

[Link] {
s:

Text("Hello Compose")
tp

}
ht

Challenges:

●​ Lifecycles mismatch​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Configuration changes​

oi
●​ Recomposition control​

n dr
-a
nu
70. How do you handle performance

ha
ris
optimization in Jetpack Compose? /k
/in
Key Techniques
m

✔ Use keys inside LazyColumn


co

Avoids wrong state & unnecessary recompositions.


n.

✔ Use @Stable / @Immutable


di
ke

Helps Compose skip recompositions.


lin

✔ Hoist state
n.

UI functions should be stateless.


//i

✔ Use derivedStateOf
s:
tp

Avoid expensive recalculations.


ht

✔ Use snapshotFlow for heavy observers

Prevents UI lag.

✔ Avoid creating objects in recomposition

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Wrap them with remember.

oi
✔ Use lazy layouts

n dr
Render only visible items.

-a
✔ Optimize Modifier order

nu
Place layout-affecting modifiers first:

ha
●​ size​

●​ padding​
ris
/k
/in
●​ background​
m
co

✔ Avoid nested layouts


n.

Use constraintLayout or custom layouts.


di
ke
lin

71. What is CompositionLocal in Jetpack


n.
//i

Compose? How does it work internally?


s:
tp

Definition
ht

CompositionLocal is a way to share data implicitly across the Compose tree without passing
it through every Composable parameter.

Similar to React Context or InheritedWidget in Flutter.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
How It Works Internally

n dr
●​ Compose stores CompositionLocal values in its slot table.​

-a
nu
●​ When you call CompositionLocalProvider, you override the value for that subtree.​

ha
●​ When a Composable reads a local, Compose tracks that read.​

ris
●​ If the local value changes → only the consumers that read that local recompose.​
/k
/in
m

Example
co

val LocalUserName = compositionLocalOf { "Guest" }


n.

@Composable
di

fun App() {
ke

CompositionLocalProvider(LocalUserName provides "Krishanu") {


lin

HomeScreen()
}
n.

}
//i
s:

@Composable
tp

fun HomeScreen() {
ht

Text("Welcome: ${[Link]}")
}

Best Practices
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Use for theme-like or global data.​

oi
✔ Don’t overuse—may hide dependencies.

n dr
-a
72. What is rememberSaveable? How does

nu
it work under the hood?

ha
Definition
ris
/k
/in
rememberSaveable stores state during:
m

●​ recomposition ✔​
co

●​ configuration change ✔​
n.

●​ process recreation (optional) ✔​


di
ke
lin

How it works
n.
//i

●​ Uses SavedStateRegistry, Bundle, and Saver.​


s:
tp

●​ Converts an object into something that can be saved inside Bundle.​


ht

Example
var name by rememberSaveable { mutableStateOf("") }

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
When to use

n dr
●​ Form fields​

-a
nu
●​ Pager/Tab index​

ha
●​ Scroll position​

ris
/k
/in
Interview Tip
m

If the value needs to survive rotation, use rememberSaveable instead of remember.


co
n.
di

73. What is the difference between


ke

SideEffect, LaunchedEffect, and


lin
n.

DisposableEffect?
//i
s:

API When it runs Use Case


tp

SideEffect After every successful recomposition Logging, analytics


ht

LaunchedEffect Runs a coroutine when key changes Fetch data,


animations

DisposableEffec Setup & cleanup when key changes Add/remove listener


t

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Examples

oi
SideEffect

dr
SideEffect {

n
println("Recomposition completed!")

-a
}

nu
ha
LaunchedEffect
LaunchedEffect(Unit) {
[Link]()
ris
/k
}
/in
m

DisposableEffect
co

DisposableEffect(Unit) {
[Link]()
n.

onDispose { [Link]() }
di

}
ke
lin
n.

74. Explain the purpose of Reusable


//i
s:

Composables and how to design them.


tp
ht

Why reusable?

●​ Avoid code duplication​

●​ More consistent UI​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Easy maintenance​

oi
n dr
-a
Design Principles

nu
✔ Accept only required parameters​

ha
✔ Expose callbacks​
✔ Avoid internal state → use state hoisting​

ris
✔ Keep it stateless whenever possible
/k
/in

Example: Reusable Button


m

@Composable
co

fun PrimaryButton(
text: String,
n.

onClick: () -> Unit


di

) {
ke

Button(
lin

onClick = onClick,
modifier = [Link]()
n.

) {
//i

Text(text)
s:

}
tp

}
ht

Best Practice

Reusable components should NOT hold business logic.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
75. What are keys in

n
-a
LazyColumn/LazyRow? Why are they

nu
important?

ha
ris
Definition
/k
Keys are unique identifiers for list items in lazy layouts.
/in
m
co

Purpose
n.

●​ Helps Compose identify items during recomposition.​


di

●​ Prevents item re-creation when scrolled.​


ke

●​ Retains scroll position & internal state of items.​


lin
n.
//i
s:

Example
tp

LazyColumn {
ht

items(users, key = { [Link] }) { user ->


UserItem(user)
}
}

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
If you don’t use keys

oi
❌ Item state resets when list changes​
❌ Wrong animations​

dr
❌ Scrolling jumps

n
-a
nu
ha
76. What is MovableContent in Compose?
ris
Definition
/k
/in

movableContentOf allows a part of the UI to move inside the composition tree while
m

preserving its state.


co
n.

Example
di

val movable = movableContentOf {


ke

Text("This text preserves state when moved")


lin

}
n.

Column { movable() }
//i

Row { movable() }
s:
tp
ht

Use Cases

●​ Animated transitions between screens​

●​ Complex layouts where element moves but state must survive​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
Interview Tip

n dr
This is useful for shared element transitions.

-a
nu
ha
77. Difference between remember,
rememberSaveable, and ris
/k
/in
rememberUpdatedState.
m

Hook Purpose
co

remember Survive recomposition only


n.
di

rememberSaveable Survive recomposition + configuration change


ke

rememberUpdatedStat Give latest value to side-effects


e
lin
n.
//i

rememberUpdatedState Example
s:

@Composable
tp

fun Timer(seconds: Int) {


val latest = rememberUpdatedState(seconds)
ht

LaunchedEffect(Unit) {
delay(2000)
println([Link])
}
}

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
This ensures side-effects receive updated arguments.

n dr
-a
nu
78. What is snapshot isolation in

ha
Compose?
ris
Definition
/k
/in
Snapshot isolation ensures that state reads and writes do not conflict during recomposition.
m
co

How it works
n.
di

●​ Compose uses Kotlin snapshot system.​


ke

●​ Each recomposition reads a consistent state version.​


lin

●​ Writes create a new snapshot version.​


n.
//i
s:
tp

Benefits
ht

✔ Avoids race conditions​


✔ Ensures deterministic recomposition​
✔ Allows multi-threaded state access

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
79. What is Slot Table? How does

oi
dr
Compose store UI?

n
-a
Slot Table is Compose’s internal data structure that stores:

nu
●​ UI tree​

ha
●​ states​

●​ remembered values​
ris
/k
/in
●​ CompositionLocals​
m
co

Think of it as a compact representation of UI.


n.
di

Why Slot Table?


ke

●​ Fast lookups​
lin
n.

●​ Efficient updates​
//i

●​ Minimal memory footprint​


s:
tp
ht

How it works

When a Composable runs -> Compose stores structure in the slot table.​
During recomposition -> Only specific slots are updated -> performance gain.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
80. What is RememberObserver? What

n
-a
replaced it?

nu
ha
RememberObserver

ris
Used earlier to observe when something enters/leaves composition.

But it was deprecated.


/k
/in
m

Replacement
co
n.

Use DisposableEffect.
di
ke

Example
lin

DisposableEffect(Unit) {
n.

start()
//i

onDispose { stop() }
}
s:
tp
ht

81. Explain the different phases of


Recomposition in Jetpack Compose.
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Recomposition happens in three main phases:

oi
n dr
① Skipping Phase

-a
nu
Compose first checks if a Composable can be skipped.

ha
A Composable is skipped when:

ris
●​ No state it reads has changed​
/k
●​ No parameters changed​
/in
m

This is why stable classes matter.


co
n.
di

② Recomposition Phase
ke

Only the Composables that depend on changed state are re-executed.


lin

Compose updates:
n.
//i

●​ Slot table nodes​


s:

●​ Remembered values​
tp
ht

●​ UI nodes (if required)​

This is lightweight and incremental.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
③ Apply Phase

oi
dr
Once recomposition finishes:

n
●​ Compose applies the diff​

-a
nu
●​ UI elements update (Text, Button, Modifier changes)​

ha
This ensures only actual UI changes hit the UI layer.

ris
/k
/in
Interview Tip

❗ Recomposition ≠ rendering.​
m
co

Rendering happens only after applying changes.


n.
di
ke

82. Why is Jetpack Compose considered


lin

more testable than XML?


n.
//i

Reasons
s:
tp

✔ Composable functions are normal Kotlin functions


ht

They can be unit-tested like any other function.

✔ State-driven UI

You don’t test view mutations.​


You test the result of a given state → deterministic UI.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Compose UI Testing Framework

oi
Provides APIs like:

n dr
●​ onNodeWithText()​

-a
nu
●​ performClick()​

ha
●​ assertIsDisplayed()​

ris
/k
✔ No Flaky UI Tests
/in

Because no View inflation, no thread delays, no findViewById.


m
co
n.

Example Test
di

@Test
fun verifyButtonClick() {
ke

[Link] {
lin

CounterScreen()
n.

}
//i

[Link]("0").assertExists()
s:

[Link]("Increase").performClick()
tp

[Link]("1").assertExists()
ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
83. Explain how StateFlow and Compose

oi
dr
work together.

n
-a
Flow → Compose Integration

nu
collectAsState() converts a Flow into Compose state that triggers recomposition.

ha
Example
ris
/k
val uiState by [Link]()
/in
m
co

How it works internally


n.

●​ A coroutine runs inside LaunchedEffect​


di
ke

●​ It collects Flow emissions​


lin

●​ For each value → it updates Compose state​


n.
//i

●​ This triggers recomposition​


s:
tp
ht

Best Practices

✔ Use StateFlow in ViewModel​


✔ Use collectAsStateWithLifecycle() for lifecycle-aware collection​
✔ Avoid collecting Flow manually in Composable

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
oi
dr
84. What is derivedStateOf and when

n
-a
should you use it?

nu
ha
Definition

ris
derivedStateOf memoizes an expensive calculation based on state.
/k
/in

Why use it?


m
co

To avoid recomputing derived values on every recomposition.


n.
di

Example
ke

val filtered = remember {


lin

derivedStateOf {
[Link] { [Link] }
n.

}
//i

}
s:
tp
ht

Benefits

✔ Performance optimization​
✔ Computed only when input dependencies change

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Interview Tip

oi
Useful for lists, search filters, expensive calculations.

n dr
-a
nu
85. What is Ref in Jetpack Compose?

ha
Refs are used inside low-level Compose internals (not common in app development).

ris
Use Cases
/k
/in
●​ Accessing mutable objects during Recomposition​
m

●​ Creating stable references​


co
n.
di
ke

Example
val ref = remember { Ref<String>() }
lin

[Link] = "Hello"
n.
//i
s:

Interview Takeaway
tp
ht

Ref is rarely required.​


Most real-world apps never use it.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
86. Explain the difference between

oi
dr
[Link] vs PaddingValues.

n
-a
[Link]

nu
Used to add space FOR a Composable.

ha
Text("Hello", modifier = [Link]([Link]))

ris
/k
/in
PaddingValues
m

Used inside layouts (LazyColumn, Scaffold, etc.) to provide padding TO children.


co

Example in LazyColumn:
n.

LazyColumn(
di

contentPadding = PaddingValues([Link])
ke

)
lin
n.
//i

Key Difference
s:

[Link] PaddingValues
tp

Applied on the Passed to layout to apply


ht

Composable internally

Part of Modifier chain Value container

Affects measurement Used by layouts

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
87. What are Reusable Modifiers and why

oi
dr
should you create them?

n
-a
Reusable modifiers help maintain clean code and consistent design.

nu
ha
Example

ris
fun [Link]() = [Link]( /k
[Link]([Link], RoundedCornerShape([Link]))
)
/in
m

Usage:
co

Box(modifier = [Link]())
n.
di
ke

Benefits
lin
n.

✔ Reduces duplication​
✔ Uniform UI​
//i

✔ Makes UI code readable


s:
tp
ht

Interview Tip

Modifiers can be combined using .then() but order matters.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
88. What are Skippable (Stable) and

oi
dr
Non-Skippable (Unstable) Composables?

n
-a
Stable

nu
Composable’s parameters did not change → Skip recomposition.

ha
Unstable

Composable must recompose every time.


ris
/k
/in
m

Stable Classes Properties


co

A type is stable if:


n.

●​ Its properties don’t change without changing the reference​


di
ke

●​ They are immutable​


lin

●​ Marked with @Immutable, @Stable, or recognized by compiler​


n.
//i
s:
tp

Example Stable
ht

@Immutable
data class User(val id: Int, val name: String)

Why stable matters?


Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Compose skips recomposition​

oi
✔ Improves performance​
✔ Cleaner UI rendering

n dr
-a
nu
89. What is animate*AsState API in

ha
Jetpack Compose?
ris
Used for simple, single-value animations.
/k
/in
m

Example
co

val alpha by animateFloatAsState(targetValue = if (visible) 1f else


n.

0f)
di
ke
lin

How it works
n.

●​ Monitors the target value​


//i

●​ Starts animation when target changes​


s:
tp

●​ Emits intermediate values​


ht

●​ Triggers recomposition until animation ends​

Best Use Cases


Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Opacity​

oi
✔ Color​
✔ Size​

dr
✔ Rotation

n
-a
nu
Interview Tip

ha
For complex animations, use updateTransition.

ris
/k
/in

90. Explain updateTransition and when to


m

use it.
co
n.

updateTransition allows multiple animations to run based on a single state.


di
ke
lin

Example
n.

val transition = updateTransition(targetState = isExpanded)


//i

val alpha by [Link] { if (it) 1f else 0.5f }


s:

val size by [Link] { if (it) [Link] else [Link] }


tp
ht

Why use it?

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Synchronize multiple animations​

oi
✔ Cleaner animation code​
✔ Smooth UI transitions

n dr
-a
Interview Tip

nu
ha
Perfect for expandable cards & complex animated UI widgets.

ris
/k
91. What is a Slot Table in Jetpack
/in
m

Compose? Explain its role in composition.


co

The Slot Table is one of the core internal data structures Compose uses to track:
n.
di

●​ UI tree structure​
ke

●​ Remembered values​
lin

●​ Composition groups​
n.
//i

●​ State references​
s:
tp

It is essentially the Compose virtual UI tree.


ht

✔ How Slot Table Works


Each Composable invocation creates:

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Group (a node)​

oi
●​ Position in Slot Table​

n dr
●​ Any remembered objects → stored in slots​

-a
nu
●​ Keys → to restore state later​

ha
When recomposition occurs, the slot table:

ris
●​ Compares new composition with previous​ /k
/in
●​ Determines which nodes need updating​
m

●​ Restores remembered states if keys match​


co

●​ Applies diffs efficiently​


n.
di

❗ Why Slot Table is Important


ke
lin
n.

●​ Enables skipping recomposition​


//i

●​ Enables state preservation​


s:
tp

●​ Enables fast UI updates​


ht

●​ Avoids expensive layout traversals like XML​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Interview Tip

oi
dr
You don't manipulate slot tables yourself → but understanding it shows strong knowledge of
Compose internals.

n
-a
nu
ha
92. Explain the function & role of the
Composer.
ris
/k
/in
The Composer is the engine that:
m

●​ Executes @Composable functions​


co

●​ Writes UI structure to slot table​


n.

●​ Tracks state reads​


di
ke

●​ Decides when to recompose​


lin

●​ Manages remember {} values​


n.
//i
s:
tp

✔ Responsibilities of Composer
ht

1. Record Composition

It listens to every Composable and records its structure.

2. Trigger Recomposition

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
When state changes → Composer marks affected nodes as dirty.

oi
3. Restore Remembered Values

n dr
When nodes are re-executed, Composer matches keys → restores values.

-a
nu
4. Apply UI Changes

ha
After recomposition → Composer issues UI updates to rendering layer.

ris
/k
Interview Summary
/in
m

Composer = Heart of Jetpack Compose runtime.


co
n.
di

93. What is Skipping and Why it is crucial


ke

for performance?
lin
n.

Skipping means:​
//i

A composable is not recomposed when its inputs and read states haven’t changed.
s:
tp

✔ When skipping happens?


ht

●​ Stable parameters unchanged​

●​ No new state reads​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ No effects triggered​

oi
n dr
-a
✔ Why skipping matters?

nu
●​ Boosts performance massively​

ha
●​ Prevents unnecessary UI work​

●​ Minimizes layout & draw operations​


ris
/k
/in
m
co

Example
n.

@Composable
di

fun NameCard(name: String) {


Text(name) // Skipped if name is stable & unchanged
ke

}
lin
n.
//i

Interview Note
s:

Compose performance = ability to skip intelligent recompositions.


tp
ht

94. What are Keys in Compose? Explain


stable vs unstable keys.
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Keys allow Compose to:

oi
●​ Identify items in lists​

n dr
●​ Preserve state for each composable​

-a
●​ Avoid recomposing wrong items​

nu
ha
✔ Example ris
/k
/in
items(users, key = { [Link] }) { user ->
UserRow(user)
m

}
co
n.

[Link] stabilizes identity → Compose knows which slot belongs to which element.
di
ke
lin

Stable Key
n.

●​ Same value on every recomposition​


//i
s:

●​ Does NOT change unexpectedly​


tp

●​ Ideal: unique IDs​


ht

Unstable Key
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Changes frequently → Compose may lose track of state.

oi
Example bad key:

n dr
key = { [Link]() }

-a
nu
ha
Interview Tip

ris
Keys = foundation of LazyColumn performance + state correctness.
/k
/in

95. What is the Recomposer? Explain how


m
co

it works behind the scenes.


n.
di

The Recomposer monitors state changes and schedules recompositions.


ke
lin

✔ How It Works
n.
//i

1. State gets updated


s:
tp

E.g., count++ updates mutableStateOf.


ht

2. Snapshot system marks changed state

Snapshots detect write operations.

3. Recomposer collects affected nodes

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
It scans slot table and builds a list of groups to recompose.

oi
4. Recomposition is executed

n dr
Composer re-executes only the dirty composables.

-a
nu
5. UI changes applied

ha
Diffs are applied to UI tree efficiently.

ris
/k
Interview Advantage
/in
m

Shows deeper understanding of Compose runtime.


co
n.
di

96. What is the Snapshot system in


ke

Compose?
lin
n.

This is the state management engine behind mutableStateOf.


//i
s:
tp

✔ Key Features
ht

●​ Tracks read and write operations​

●​ Prevents concurrent modification issues​

●​ Supports transactions​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Ensures consistency during recomposition​

oi
n dr
-a
Example (concept)

nu
[Link]()

ha
ris
Compose is built on multiversion concurrency control (MVCC).
/k
/in

Interview Tip
m

Snapshot system = foundation of reactive recomposition.


co
n.
di
ke

97. How do animations work internally in


lin

Compose?
n.
//i

Compose animations are:


s:

●​ State-driven​
tp
ht

●​ Frame-based​

●​ Coroutine-backed​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
✔ Internals

oi
dr
1. Animation state changes (targetValue).

n
-a
2. AnimationClock emits frame timestamps.

nu
3. Value interpolated (tween, spring, keyframes).

ha
4. Each frame triggers recomposition.

5. UI updates only for animated nodes.


ris
/k
/in
m

Types of animations
co

●​ animate*AsState → simple one-value​


n.
di

●​ updateTransition → multiple values​


ke

●​ AnimatedVisibility → enter/exit animations​


lin
n.

●​ Animatable → fine control​


//i
s:
tp

Interview Tip
ht

Animations can cause performance issues → use wisely.

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
98. What is SubcompositionLayout and

oi
dr
why is it used?

n
-a
SubcomposeLayout allows deferred composition.

nu
ha
✔ Use Cases
ris
●​ Compose content depending on measured size​
/k
/in

●​ Collapsing toolbar​
m

●​ Tabs​
co
n.

●​ Custom layouts requiring two-pass measurement​


di
ke
lin

Simple Concept Example


n.

SubcomposeLayout { constraints ->


//i

val header = subcompose("header") { Header() }


s:

val headerPlaceable = [Link]().measure(constraints)


tp
ht

val body = subcompose("body") { Body([Link]) }


val bodyPlaceable = [Link]().measure(constraints)

layout(width, height) {
[Link](0, 0)
[Link](0, [Link])
Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
}

oi
}

n dr
-a
Interview Tip

nu
This is one of the toughest advanced Compose UI concepts → rarely used but highly important.

ha
ris
/k
99. What is Pointer Input System in
/in

Compose?
m
co

Used for custom gesture handling.


n.
di
ke

✔ Example: Detect Drag


lin

[Link](Unit) {
n.

detectDragGestures { change, dragAmount ->


//i

// Handle drag
}
s:

}
tp
ht

Internally

●​ Uses coroutine suspending handlers​

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
●​ Handles multi-touch events​

oi
●​ Integrates with gesture detectors​

n dr
-a
nu
Common APIs

ha
●​ detectTapGestures​

ris
●​ detectDragGestures​
/k
/in
●​ scrollable​
m

●​ pointerInteropFilter (to use View-based gestures)​


co
n.
di
ke

100. What is the difference between


lin

Gesture Detectors and Pointer Input


n.
//i

Modifiers?
s:
tp

Feature Pointer Input Gesture Detectors


ht

Level Low-level API High-level abstraction

Usage Custom gestures Common gestures

Complexity Harder Easier

Krishanu Nandan
Senior Android Developer
Follow - [Link]
d
Example detectDragGesture [Link]

oi
s

n dr
-a
Example Gesture Detector (Click)

nu
[Link] { }

ha
Example Pointer Input ris
/k
/in
[Link](Unit) {
awaitPointerEventScope {
m

// Advanced gestures
co

}
n.

}
di
ke

Interview Tip
lin
n.

Pointer input system is powerful but rarely needed for standard UIs.
//i
s:
tp
ht

Krishanu Nandan
Senior Android Developer
Follow - [Link]

You might also like