onResume is a lifecycle method in Android that is called when an Activity or Fragment comes to the foreground and gains input focus. In this state, the screen is ready for user interaction: all touch events, key presses, and gestures are directed to this component. onResume is the working state of an Activity where the app spends most of its time. This is where you open the camera, start video playback, begin speech recognition, and register sensor listeners that require exclusive access. For more on the full Activity lifecycle, read the article Activity Lifecycle.
Key Takeaways
onResume — the third lifecycle method of an Activity, called after onStart, which signals that the screen is ready for full user interaction. At this moment, the Activity is at the top of the back stack, the system directs all input events to it, and the app can begin any operations requiring active user participation: video calls, games, audio recording, drawing on Canvas.
onResume is part of the “foreground lifetime” — the interval between onResume and onPause. This is the most active period of an Activity, when the app consumes the most resources: CPU for touch processing, GPU for rendering animations, camera and microphone for video capture. Understanding this lifecycle level is critical for optimizing power consumption — resources opened in onResume must be immediately closed in onPause.
According to Google I/O 2025, the average time an Activity spends in the onResume state per session is 2–5 minutes for news apps and 15–30 minutes for games and messengers. All other time the Activity is in onPause, onStop, or onDestroy states. This means optimizing specifically the onResume code yields the greatest performance and battery life gains.
In an Activity, the onResume method is called every time the screen gains input focus — on first launch, when returning from another Activity, when closing a dialog, when unlocking the device. This is a “hot” method that can be called many times per session, and its implementation must be as lightweight as possible.
class CameraActivity : AppCompatActivity() {
private var cameraProvider: ProcessCameraProvider? = null
private var preview: Preview? = null
override fun onResume() {
super.onResume()
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
preview = Preview.Builder().build().also {
it.setSurfaceProvider(binding?.viewFinder?.surfaceProvider)
}
try {
cameraProvider?.unbindAll()
cameraProvider?.bindToLifecycle(
this, cameraSelector, preview
)
} catch (e: Exception) {
Log.e("Camera", "Failed to bind camera", e)
}
}, ContextCompact.getMainExecutor(this))
}
override fun onPause() {
super.onPause()
cameraProvider?.unbindAll()
preview = null
}
}
The CameraX example demonstrates the classic use of onResume/onPause: the camera is an exclusive resource that only one app can use at a time. Binding the camera to the lifecycle via bindToLifecycle automatically closes the camera in onPause, but an explicit unbindAll call guarantees immediate release. This is especially important when switching between Activities: the camera must be released before another Activity tries to open it.
onResume in a Fragment is called after the containing Activity has received onResume. However, due to FragmentManager and ViewPager specifics, the onResume call for a Fragment may be delayed relative to the Activity. For example, a Fragment in a ViewPager with offscreenPageLimit = 1 receives onResume only when it becomes the current page, not at Activity start.
class VideoPlayerFragment : Fragment() {
private var exoPlayer: ExoPlayer? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
exoPlayer = ExoPlayer.Builder(requireContext()).build()
binding?.playerView?.player = exoPlayer
}
override fun onResume() {
super.onResume()
exoPlayer?.play()
if (userVisibleHint) {
startBiometricAuth()
}
}
override fun onPause() {
exoPlayer?.pause()
stopBiometricAuth()
super.onPause()
}
}
The userVisibleHint check in Fragment.onResume is relevant for ViewPager: a Fragment may receive onResume but be hidden by a neighboring page (for example, during an animated transition). In such cases, starting video or biometrics in onResume without a visibility check will lead to unexpected behavior. Starting with Fragment 1.5.0, it is recommended to use FragmentTransaction.setMaxLifecycle() for precise control over fragment lifecycle in ViewPager2.
Developers often confuse onStart and onResume, placing code in the wrong method. The main rule: onStart — for resources that work while visible; onResume — for resources that require input focus. Let’s look at specific scenarios and the correct method choice.
| Operation | Method | Rationale |
|---|---|---|
| Geolocation subscription | onStart / onStop | GPS can work with partial visibility |
| Opening the camera | onResume / onPause | Camera is an exclusive resource |
| BroadcastReceiver | onStart / onStop | System events don’t require focus |
| Video playback | onResume / onPause | Video must be visible to the user |
| Bluetooth scanning | onStart / onStop | Scanning can run in the background |
| Voice recorder (MediaRecorder) | onResume / onPause | Recording requires active UI |
| Sensor listeners | onResume / onPause | Sensors for games and gestures |
| Data refresh | onStart | Fresh data needed on appearance |
A practical rule: if an operation should be interrupted when a dialog appears — use onResume/onPause. If an operation can continue when the screen is partially covered — use onStart/onStop. For example, a video player should pause the video when a dialog opens (onPause), while geolocation can continue updating (remains in onStart).
Exclusive resources are device components that can only be used by one application at a time. Camera, microphone, video output (MediaProjection), NFC adapter in read mode, USB devices in accessory mode — all these resources must be opened in onResume and released in onPause.
MediaRecorder is used for recording audio and video. Permission requests and MediaRecorder preparation are done in onCreate, while recording starts in onResume. If the user switches to another app, onPause pauses recording, and onResume resumes it. This is standard behavior for voice recorders and video recording apps.
private var mediaRecorder: MediaRecorder? = null
private var isRecording = false
override fun onResume() {
super.onResume()
if (isRecording) {
mediaRecorder?.resume()
}
}
override fun onPause() {
if (isRecording) {
mediaRecorder?.pause()
}
super.onPause()
}
Biometric authentication (BiometricPrompt) should only be called when the Activity is in onResume. If called in onCreate or onStart, the biometric dialog may appear before the Activity finishes initialization, leading to incorrect result handling. Calling it in onResume ensures the biometric window is shown in the correct context.
Let’s look at three proven patterns for working with onResume used in commercial projects: inactivity timer reset, updating visible data, and integrating with Jetpack Navigation.
In apps with sensitive data (banking, medical records), onResume is used to reset the auto-logout timer. If the user is actively interacting with the app, onResume is called on every screen transition, and the timer resets. If the user minimizes the app, onPause stops the timer, and onResume upon return either resets it or requests re-authentication.
A list that must display up-to-date data every time the screen is revisited is updated in onResume. For example, if the user created a new entry in another Activity and navigated back, onResume reloads the list from the local database or ViewModel cache. This ensures data consistency without manual notifyDataSetChanged calls.
override fun onResume() {
super.onResume()
// ActivityResultLauncher returned a result — refreshing the list
viewModel.refreshList()
// Inactivity timer reset
inactivityTimer.reset()
}
In Jetpack Navigation, onResume of a fragment is called every time you return to it via back navigation. This property is used to reset UI state: hide the keyboard, clear search fields, update the toolbar title. OnBackPressedCallback combined with onResume gives full control over navigation without code duplication.
Frequently Asked Questions
onStart — the screen is visible. onResume — the screen is active and ready for interaction. Imagine: you are watching TV (onStart), but you pick up the remote (onResume). The TV is always visible, but interaction only starts with the remote. If someone covers the TV with a curtain — the screen is no longer visible (onStop). If someone takes the remote away — interaction stops (onPause), but the TV is still visible.
onResume is called every time the Activity gains input focus. The minimum is once (on launch). The maximum depends on usage scenarios: switching between screens, opening dialogs, quickly locking and unlocking the device — each such scenario calls onResume upon returning to the screen.
The camera is an exclusive resource available to only one app at a time. If you open the camera in onCreate or onStart, it will remain locked for other apps even when your app is inactive. onResume guarantees the camera is open only when the Activity is in the foreground, and onPause immediately closes it. This is an Android development standard, established in the CameraX and Camera2 API documentation.
Yes, onResume may not occur if an Activity is overlapped by another Activity right after appearing. For example, Activity A starts Activity B in the onCreate or onStart method. In this case, A receives onStart → onPause → onStop, skipping onResume. The system does not call onResume because Activity A never received input focus.
In onResume, you must not perform long synchronous operations: loading large data from the network, complex SQL queries, image processing. onResume runs on the UI thread, and any blocking longer than 100–200 ms causes UI lag. All heavy operations should be asynchronous — via coroutines, RxJava, or WorkManager. It is also not recommended to call finish() in onResume without checking — this can lead to an infinite recreation loop.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also