Mobile Apps: Connectivity Loss When In Background
One mobile caveat that surprised me: when the app goes to background, network behavior can become unreliable, and right after returning to foreground there is usually a small window where requests still fail.
In our case, this showed up around OAuth redirects. The browser opens, app goes to background, then callback returns to the app, and the first API call can fail for around 100-150ms even though everything looks correct.
What Worked for Us
Keeping a background timer active before the app is backgrounded helped us reduce these failures. Using react-native-background-timer for this flow is the practical fix we ended up with. Metamask uses a similar approach.
BackgroundTimer.runBackgroundTimer(() => {
// noop
}, 3000);
This keeps the app from sleeping for a short period, but not forever. In practice, you usually get up to around 2 minutes before the OS forces the app to hibernate/sleep in background.
Alternatives Worth Considering
The timer approach is not the only option. Another practical option is to queue callback-dependent requests until app state is fully active, then retry with a short backoff (for example 100ms, then 250ms). This adds a bit more logic, but it avoids firing sensitive requests in that unstable return window.
A heavier alternative is moving more of the OAuth completion logic to backend-controlled flows so the app does less immediate work on return. This can improve reliability, but it increases implementation complexity.
Conclusion
If your OAuth callback flow seems randomly flaky, check app lifecycle timing first.
In mobile apps, “app is visible again” does not always mean “network stack is fully ready.” A small delay strategy, or a background timer approach, can save a lot of intermittent failures.