← Back to list

Android Interview Questions — Jetpack Compose

1. What is Jetpack Compose?

Rajiv R · 2026-06-12 23:02 · 0 claps · 6.1 min read
#android-interviews #jetpack-compose #modern-interview
Open on Medium ↗
Wiki topics: 📱 · Mobile Development

Android Interview Questions — Jetpack Compose

1. What is Jetpack Compose?

Basically, Jetpack Compose is the modern way we build Android UIs. The biggest change is that we’ve moved away from XML entirely and now use 100% Kotlin.

  • Why it’s better: It’s a ‘declarative’ toolkit. Instead of manually managing every view, we just describe what the UI should look like for a specific state, and Compose handles the rest. It’s much faster and generally requires a lot less code.

2. What is a Composable function, and how do you define one?

I like to think of a Composable function as the basic ‘Lego block’ of the UI. It’s a regular Kotlin function, but with three specific rules:

  • Annotation: We mark it with @Composable. This tells the compiler that this function is meant to draw something on the screen.
  • Name: By convention, we always start the name with a Capital letter (PascalCase).
  • Job: Its only job is to take in data as parameters and transform that data into a UI hierarchy. You just call one Composable inside another to build your screen.

3. How does Jetpack Compose differ from XML-based UI?

There are couple of big differences:

  • Declarative vs. Manual: In the old XML way, it was ‘imperative.’ You had to manually find a view using findViewById and then tell it to change. In Compose, the UI is ‘smart’ — it watches the state, and when the state changes, the UI updates itself automatically.
  • One Language (Kotlin): It’s all Kotlin now. You don’t have to jump back and forth between an XML file and a Kotlin file anymore. This makes it much easier to catch errors and reuse code.
  • Less ‘Extra’ Stuff: It gets rid of all the ‘boilerplate.’ You don’t need View Binding, Layout Inflators, or complex custom View classes anymore. In my experience, you can usually build a screen with about 50% less code than you would need with XML.

4. Explain the Jetpack Compose Lifecycle.

The Jetpack Compose lifecycle consists of three main phases:

  • Composition: The initial phase where Compose executes your functions for the first time to build the UI tree.
  • Recomposition: Triggered when the state changes. Compose re-executes only the affected composables to update the UI efficiently.
  • Disposal: Occurs when a composable leaves the UI tree (e.g., navigating away). This phase cleans up resources and cancels active coroutines or effects.

5. What is a Modifier in Jetpack Compose?

Basically, a Modifier is a way to ‘tell’ a Composable how to look or behave without changing the Composable itself. I think of it as a customizer.

  • Modifiers are stateless. They do not hold or manage state.
  • Modifiers are chainable. They can be chained to apply multiple properties sequentially, creating a flexible way to build complex UI behaviors.
  • Modifiers are reusable. They are designed to be highly reusable, allowing you to define them once and apply them to multiple composables.

6. How do you handle orientation changes in Jetpack Compose?

In Compose, orientation changes are handled as Configuration Changes. Basically, when the phone rotates, Android triggers a recomposition. The UI functions run again with the new screen dimensions, so the layout adapts automatically.

The most important part for a developer is state. I can use rememberSaveable to make sure that when the screen rotates, the user doesn’t lose their data — like text they already typed into a form.

7. How does Recomposition work in Jetpack Compose?

Recomposition is the process of re-executing composable functions to update the UI when their underlying state changes.

  • Trigger: It starts when a State object (like mutableStateOf) is modified.
  • Intelligent Tracking: Compose tracks which composables read which state. When a specific state changes, only the functions that depend on it are re-executed.
  • Efficiency: It skips any composables whose inputs haven’t changed, ensuring high performance by avoiding unnecessary UI redrawing.

8. What is the purpose of “remember” in Jetpack Compose?

I like to think of remember as the short-term memory of a Composable function.

  • The Problem: Normally, a function ‘forgets’ its variables every time it runs. Since Compose functions run over and over again (recomposition), they would constantly reset their data.
  • The Solution: remember tells Compose to cache a value during the first run. Every time the UI updates after that, Compose just grabs the saved value from the cache instead of recreating it.
  • The Limit: The only catch is that this memory is tied to the lifecycle of the Composable. If you navigate away or rotate the screen, that memory is cleared.

9. Explain “rememberSaveable” and how it’s different.

If remember is short-term memory, then rememberSaveable is persistent memory.

  • The Big Difference: The main difference is Screen Rotation (or configuration changes). If you use remember and rotate the phone, your data is gone. But rememberSaveable survives that.
  • How it works: It automatically saves your data into a Bundle. So when the Activity is recreated after a rotation, it just restores the value.
  • When to use it: I use rememberSaveable for anything the user has interacted with — like text they’ve typed into a search bar or the scroll position of a list. You don’t want the user to lose their work just because they turned their phone sideways.

10. What are SideEffects in Jetpack Compose?

Basically, a SideEffect is any code that escapes the UI. Since Compose functions can run hundreds of times (recomposition), you can’t just put a network call or a log statement inside a function — it would run way too often.

SideEffects are the tools we use to say: ‘Only run this code at a specific time, and not every time the UI updates.

11 . Can you explain the common SideEffect APIs?

I usually group these by how they are triggered. There are five that I use most often:

  • LaunchedEffect: I use this for background tasks that should start automatically when the screen loads — like fetching data. It takes a ‘key,’ and if that key changes, it cancels the old task and starts a new one. It’s perfect for showing a Snackbar when an error state changes.
  • DisposableEffect (The ‘Cleanup’ Task): This is for when I need to clean up after myself. For example, if I add a listener to a sensor, I use onDispose to remove it when the user leaves the screen. It’s my main tool for preventing memory leaks.
  • rememberCoroutineScope (The ‘Manual’ Task): Unlike LaunchedEffect, I use this for user actions. If I need to start a coroutine inside a button click, this gives me a safe scope that is still tied to the UI lifecycle.
  • rememberUpdatedState (The ‘Live Reference’): I use this to keep a reference to a value that might change without restarting the effect. For example, if a timer is running and the ‘onFinish’ callback changes, this lets the timer use the latest callback without having to stop and restart the whole timer.
  • SideEffect (The ‘Logger’): This is for simple tasks that need to run after every successful update of the UI. I mostly use it for things like logging analytics to see how often a screen is being recomposed.

12. How to achieve Relative Positioning in Jetpack Compose?

In Compose, we don’t have one single RelativeLayout like we did in XML. Instead, we use a few different tools depending on what we’re trying to build.

  • The “Stacking” way (Box): If I need things to overlap — like putting a play button on top of a video thumbnail — I use a Box. I then use alignment modifiers to pin things to the center, the bottom-right, or any other corner. It’s much simpler than the old way.
  • The “Linear” way (Row & Column): For most things, I just use Rows and Columns. By using ‘Weights’ and ‘Arrangements,’ you can position items relative to each other very easily without needing complex constraints.
  • The “Complex” way (ConstraintLayout): If the UI is really complicated — with many views depending on each other’s positions — I use ConstraintLayout. It works just like the XML version where you ‘anchor’ one view to another, but it’s all done in Kotlin code.
  • The “Nudge” way (Offset Modifier): And if I just need to move an element slightly without affecting the items around it, I use Modifier.offset. It’s like a precise nudge to get the position exactly right.

13 . How do you test UI components in Jetpack Compose?

Jetpack Compose provides a testing framework that allows you to write tests for UI components. You can use the @Composable test rule and the composeTestRule to interact with and assert the behavior of Composable functions and UI elements

14. What is State in Jetpack Compose?

State in Jetpack Compose represents data that can change over time and that Compose uses to update the UI when it changes. It allows the UI to automatically respond to changes in underlying data.

15. What are the two different types of state?

  • Local State: Local state is the state managed within a single composable function. It’s typically used for UI elements that don’t need to share their state with other parts of the UI. Local state is created using remember and mutableStateOf, which retain values across recompositions within the same composable.
@Composable
fun Counter() {
 // Local state
  var count by remember { mutableStateOf(0) }
  Button(onClick = { count++ }) {
     Text("Clicked $count times")
   }
}
  • Shared State: In this pattern, the state is moved up to a shared parent component, making it easier to manage across different parts of the UI.
@Composable
fun ParentComposable() {
   var sharedCount by remember { mutableStateOf(0) } // Shared state
   ChildComposable(sharedCount, onClick = { sharedCount++ })
}

@Composable
fun ChildComposable(count: Int, onClick: () -> Unit) {
 Button(onClick = onClick) {
   Text("Shared count: $count")
 }
}

메타데이터
post_id
05c5bb60d9c3
slug
android-interview-questions-jetpack-compose-05c5bb60d9c3
url
https://medium.com/@rajivjam/android-interview-questions-jetpack-compose-05c5bb60d9c3
canonical_url
https://medium.com/@rajivjam/android-interview-questions-jetpack-compose-05c5bb60d9c3
author_url
https://medium.com/@rajivjam
status
ok
fetched_at
2026-06-13 12:55:53