← Back to Cross-platform mobile foundation team

Skill · Version 1.0.0

Resilient mobile lifecycle

Preserves meaningful mobile state through backgrounding, process death, network changes and renewed authentication.

mobile-lifecycle-resilience

Team members using this skill

See how it helps

When is it useful?

Use when returning to an app loses work or starts duplicate requests.

What does it help you do?

  • Defines restoration across active, inactive, background and terminated states.
  • Handles interrupted transfers and changing network connections.
  • Coordinates one token refresh and cleans up listeners and resources.

Try asking this

Resume an upload after network switching and process restart without creating a second server-side item. Switch from Wi-Fi to mobile data, terminate the app and reopen it. Resume from confirmed progress and verify one completed remote object.

Detailed documentation

Read the skill’s original instructions, examples and checks in their authored language.

Details…Show less

Mobile Lifecycle & Resilience

Mobile apps run in an interruptible environment: phone calls, app switching, OS memory pressure, process death and radio handoffs (Wi-Fi to cellular) happen mid-operation. Design every flow to survive interruption without losing user work or leaking resources.

1. Handle every lifecycle transition (active / inactive / background / process death)

  • On inactive / background (AppState in React Native, AppLifecycleListener in Flutter, ScenePhase / LifecycleObserver in native):
    • Immediately pause camera previews, audio/video playback, high-frequency timers, sensor/GPS polling and continuous animations.
    • Flush or checkpoint unsaved form drafts and in-progress state to local storage synchronously or immediately—the OS may kill the backgrounded process without further warning.
  • On active (foreground resume):
    • Re-validate session/token expiry, refresh stale time-sensitive queries, and reconcile the status of any in-flight mutation or payment that was interrupted.
    • Re-check runtime permissions (camera, location, notifications) that the user may have toggled in OS Settings while away.
  • OS process death & state restoration: never rely solely on in-memory singletons surviving backgrounding; restore screen routes by ID and reload data or persisted drafts on cold/warm restart.

2. Flaky networks, radio switches and interrupted transfers

  • Connectivity != reachability: NetInfo / connectivity_plus reporting Wi-Fi does not mean the API is reachable (captive portals, blackholed cellular handoffs). Enforce explicit connect/read timeouts (10-30s) and distinguish network/timeout errors from 4xx business rejections.
  • Never destroy user input on failure: if a form save, comment or upload fails due to a timeout or connection drop, keep the user's draft intact on screen and provide a clear Retry action.
  • Background & chunked transfers: iOS and Android throttle background sockets within seconds; for large media uploads/downloads, show progress, support cancellation/resume, and use OS background transfer APIs (URLSession background config, Android WorkManager, expo-file-system background tasks) when work must survive app switching.

3. Single-flight token refresh and resource cleanup

  • Guard 401 Unauthorized token refresh with a single-flight mutex/promise so 5 concurrent requests resuming after foregrounding await one refresh call instead of racing and triggering false logouts.
  • Remove every AppState, NetInfo, keyboard, notification, stream and timer listener in useEffect cleanup / dispose() / onCleared().

Before you finish

  • Backgrounding pauses sensors/media/timers and checkpoints unsaved drafts before potential OS process death.
  • Foregrounding refreshes stale data, reconciles pending work and re-verifies OS permissions.
  • Network timeouts/drops preserve user input and offer safe retry without infinite loops.
  • Concurrent 401 token refreshes share a single-flight lock; all listeners and timers are cleaned up.

Included files 2

  • LICENSE.txt
  • SKILL.md