DEV Community

Juego Studios
Juego Studios

Posted on

Handling Interrupted Sessions on Android: Saving State When Calls, Low Battery and App Switching Hit Your Players

Every mobile game gets interrupted. A phone call comes in mid-match, a low-battery dialog pops up, a player switches to a messaging app to reply to a friend, or the commute train drops into a tunnel and the OS decides your game is the first thing to kill. Players in the US don't blame Android for that. They blame your game when they come back and their run, their purchase or their last ten minutes of progress is gone.

This is a practical checklist for handling interrupted sessions on Android, written with US mobile players in mind but useful anywhere. It assumes Unity or a native/Kotlin layer, but the ideas carry over to Godot and Unreal too.

1. Treat onPause as your last guaranteed moment

On Android you can't count on onStop or onDestroy running before the process is killed. The safe assumption is that onPause (or Unity's OnApplicationPause(true)) is the last callback you reliably get.

  • Save anything a player would be upset to lose in that callback, not on a timer that might not fire.
  • Keep the save small and fast. If serializing the whole world takes hundreds of milliseconds, split state into a quick "resume snapshot" and a slower full save that happens at natural checkpoints.
  • In Unity, also handle OnApplicationFocus(false), since some interruptions (notification shade, overlays, system dialogs) cause a focus loss without a full pause.
void OnApplicationPause(bool paused)
{
    if (paused)
    {
        SessionSnapshot.Capture(currentRun);   // small, fast, synchronous
        SaveSystem.WriteSnapshot();            // flush to disk now
        Time.timeScale = 0f;
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Decide what "resume" means for each game mode

Not every interruption should restore the exact frame. Write down, per mode, what the player sees when they return:

Mode On return
Single-player level Restore to the moment of pause, show a "Tap to continue" overlay
Timed puzzle Restore, but pause the clock until the player taps
Real-time PvP match Reconnect if the match is still alive, otherwise show the result and any rewards
Store / checkout Re-query purchase state before showing anything

The key rule: never drop the player straight back into live action. Always resume behind a pause overlay so a call that ends mid-boss-fight doesn't cost them a life.

3. Assume the process was killed, and test that path

The common bug isn't the pause itself. It's the cold start afterwards. When Android reclaims memory, your app restarts from scratch and only what you wrote to disk survives.

Test it on purpose:

  • Turn on Developer options → Don't keep activities and switch away from the game mid-session.
  • Use adb shell am kill <your.package.name> while the game is in the background, then reopen it from Recents.
  • Check that the game detects a pending snapshot on launch and offers to resume instead of going to the title screen with nothing.

4. Handle low battery and Battery Saver gracefully

Low-battery warnings are an interruption too, and Battery Saver can throttle CPU, cap frame rate and restrict background work.

  • Listen for battery and power-save state changes (PowerManager.isPowerSaveMode() on the native side) and offer a lower-power mode: reduced frame rate, fewer particles, shorter vibration.
  • Save a snapshot when the battery crosses a low threshold, before the phone shuts down on its own.
  • Don't rely on background jobs to finish uploads once the screen is off. Queue them and retry on the next foreground session.

5. Protect purchases and rewards across interruptions

Interruptions during checkout cause the most support tickets.

  • With Google Play Billing, always call queryPurchasesAsync() on resume and on cold start, and acknowledge or consume any purchase you haven't processed yet. Purchases that are never acknowledged are refunded automatically after a few days.
  • Grant rewarded-ad rewards from the ad SDK's reward callback and persist them immediately, so a player who switches apps right after the ad still gets what they watched it for.
  • Make reward grants idempotent (keyed by a transaction or reward ID) so a replayed callback after a restart doesn't double-grant.

6. Make multiplayer reconnects forgiving

Calls and app switches are the most common reason a mobile player "disconnects" from a match.

  • Give the server a short grace window before treating a player as gone, and let the client rejoin the same session with a token stored in the snapshot.
  • On return, show the current match state clearly ("You were away for 40 seconds, the round is still on") rather than silently snapping them back in.
  • Decide in advance what happens to an AFK player's score or team slot so it's consistent and explainable in your support FAQ.

7. Add interruption cases to your release checklist

Bake these into QA for every build, not just launch:

  • [ ] Incoming call during gameplay, during a cutscene and during checkout
  • [ ] App switch and return after 10 seconds and after 10 minutes
  • [ ] Process kill in the background, then resume from Recents
  • [ ] Low-battery dialog and Battery Saver turned on mid-session
  • [ ] Airplane mode on and off during an online match
  • [ ] Screen lock and unlock while a rewarded ad is playing

A game that comes back exactly where the player left it feels polished, even if they never notice why. If you're planning a new title or tightening up an existing one, our team works on this kind of lifecycle and device testing as part of end-to-end Android game development.

If you're preparing a US soft launch, we also wrote about tuning loot and progression in a mobile RPG before a soft launch, which pairs well with the session-handling work above.

What's the strangest interruption bug you've shipped? Share it in the comments.

Top comments (0)