← Back to Finn
AgentFinn
1. Handle every lifecycle transition (
Resilient mobile lifecycle
Preserves meaningful mobile state through backgrounding, process death, network changes and renewed authentication.
mobile-lifecycle-resilience
See how it helpsWhen 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.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
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(AppStatein React Native,AppLifecycleListenerin Flutter,ScenePhase/LifecycleObserverin 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_plusreporting 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 from4xxbusiness 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 (
URLSessionbackground config, AndroidWorkManager,expo-file-systembackground tasks) when work must survive app switching.
3. Single-flight token refresh and resource cleanup
- Guard
401 Unauthorizedtoken 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 inuseEffectcleanup /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.txtSKILL.md
