How do you run slow work like network calls or database reads in a mobile app without freezing the UI?
What the interviewer wants to hear
- The main thread draws the UI and handles touches, so it must not be blocked
- Use the platform async tools: Kotlin coroutines, Swift async/await, Dart Futures or JS promises
- Move blocking or heavy work to a background dispatcher, actor or isolate
- Update the UI back on the main thread
- Tie work to a lifecycle scope so it is cancelled when the screen goes away
Model answer
The main thread draws every frame and handles touches, so anything slow there causes jank or an ANR on Android. I use the async tools of the platform. In Kotlin I launch coroutines in viewModelScope and wrap blocking I/O in withContext(Dispatchers.IO). In Swift I use async/await, keep UI code on the main actor and let URLSession suspend instead of blocking. In Flutter, network calls are Futures, and heavy CPU work like parsing huge JSON goes to another isolate with compute or Isolate.run. In React Native I keep the JS thread free of long loops. I also tie the work to a lifecycle scope, so if the user leaves the screen the work is cancelled and nobody updates a dead view. Finally, I show loading and error states so the user always knows what is happening.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Mobile App Developer questions
- What is the difference between native and cross-platform mobile development? When would you choose each?
- Explain the lifecycle of a mobile app screen. Why does it matter?
- How do you handle network calls and errors in a mobile app?
- What is MVVM and why is it used in mobile apps?
- How do push notifications work in a mobile app?
- What options do you have for storing data on the device, and how do you choose between them?
- How do you request runtime permissions like camera or location, and what do you do when the user says no?
- How do you make your app look good on different screen sizes, orientations and font sizes?
- What is the difference between declarative UI (Compose, SwiftUI, Flutter, React Native) and the older imperative style?