Anh Tran dev notes

Production bugs from mobile and backend work, written up with the fix and how it was checked.

Note 07 / React Native / Ads / Android

Showing fullscreen ads in React Native: why timers lie on Android and what to wait for instead

JavaScript timers pause on Android while a fullscreen ad is on screen, so every timeout cap fires late and in a burst. The ad lifecycle events to trust, a stage lock for iOS, an opened-guard around show(), and the rewarded-ad grace period.

By
Trần Thế Anh, Software Engineer
Published
Work done
October 2026, React Native app (Android and iOS)
Stack
React Native, react-native-google-mobile-ads 16.x, TypeScript
Reading
5 min, 1,152 words

A boot flow in a mobile app often chains a few full screens: a splash, an app-open or interstitial ad, a “welcome back” screen, the home screen. Each hand-off needs to know when the previous screen is finished. The easy way to know is a timer. In React Native on Android, that is the wrong tool for any step that includes a fullscreen ad, because the timers stop while the ad is up.

This note records what that does, and the rules a React Native app ended up with for showing fullscreen ads without the flow running underneath them. The library version in question is react-native-google-mobile-ads 16.x, and version-specific parts are marked.

Symptom

A cap such as “if the ad has not finished in 45 seconds, continue” looks safe on paper. With a long interstitial, or a user who taps the ad and goes to the store, the boot flow continues while the ad is still on screen. The “welcome back” screen mounts underneath the ad, taps its continue button on its own timer, and when the user closes the ad they land on Home instead of the screen they should have seen.

The cause is the combination of two behaviours.

First, on Android, the React Native timer module pauses JavaScript timers when the host activity pauses (JavaTimerManager.onHostPause). A fullscreen ad is an activity on top of yours. Sit in an interstitial for 67 seconds and the 45 and 60 second caps never fire during that time. They fire in a burst when the app resumes. Events from native to JS still arrive while the timers are paused, which is what makes the next rule possible.

Second, once the cap wraps the whole show() call, a firing cap means “carry on with the flow”. The flow carries on while the ad is on screen.

Rule 1: trust events, not clocks

The only evidence that counts about an ad is what the SDK says:

Question Use Not
Is it on screen? the opened event “I called show()”
Has it left? closed or error event a 45 second cap, a 75 second watchdog
Android lost the closed event? the app state going back to active after opened, then wait 2 seconds a timer
Has a React Native <Modal> finished dismissing? its onDismiss setTimeout(550)

A timer can still exist as a last-resort net, but it has to be loud when it fires (log it), because every time it does, an event that should have arrived did not.

Rule 2: a cap applies only before show()

The time limit is for the wait to get an ad ready, which is the period before show(). After the opened event the only thing to wait for is closed or error. This one change removes the “flow continues under the ad” bug, because the code path that said “continue after 45 seconds” no longer wraps the displayed ad.

Rule 3: guard show() itself

show() returns a promise, and it can reject. Two causes seen were a null activity on Android (the app went to background just before) and a nil view controller on iOS. And in the 16.x line on Android, a failed show was not reported to JavaScript at all unless the library was patched. Upstream fixed it in 17.0.0, so on 16.x the app applied the patch in a postinstall script that exits non-zero if it cannot apply, rather than skipping silently.

So every show() call has two guards:

async function showWithGuard(ad: FullScreenAd): Promise<'opened' | 'failed'> {
  const opened = waitFor(ad, 'opened');            // resolves on the SDK event
  const guard = new Promise<'failed'>((res) =>
    setTimeout(() => res('failed'), 4000));        // no opened event within 4 s
  try {
    await ad.show();
  } catch (e) {
    log('[ads] show() rejected', e);
    return 'failed';
  }
  return Promise.race([opened, guard]);
}

The 4 second guard runs from before show() resolves, so it only covers the time to get on screen. It is not a cap on how long the ad may stay. The code above is a simplified illustration, not the app’s source. A real version also has to cancel the guard on opened, and cancel the opened listener on failure.

Rule 4: one thing presents at a time on iOS

On iOS a view controller can present only one thing. If you present a second one while the first is still on screen, the second is rejected without an error, and the first stays covering the screen. The visible symptom was an invisible modal that swallowed every tap.

The fix is a stage: a shared lock that anything which wants to present (an ad, a <Modal>) must acquire first. It waits for a limited time (8 seconds in this app), and if it expires it drops that attempt instead of presenting on top.

Rule 5: the watchdog counts foreground time

An overlay watchdog protects against a flag that never clears, so a “fullscreen ad showing” state cannot block the app forever. Written as “240 seconds after the flag was set”, it misbehaves when a user taps the ad, spends five minutes in the store and returns: the clock has already run out, and the watchdog releases the stage while the ad is still up. The fix is to count only the time the app is in the foreground.

Rule 6: rewarded ads grant on the earned event, with a grace

Reward only on the earned-reward event, never on “closed”. But on Android the earned event is not guaranteed to arrive before closed. So the code holds the result for a short grace window (4 seconds) after the dismiss, and then reports one of four outcomes: earned, dismissed, unavailable, failed.

Rule 7: clear flags in finally

A flag that says “an ad flow is in progress” is set at the start and must be cleared on every exit path, in a finally. Missing one exit (an early return after a failed load, say) leaves the flag set, and later ads are refused with no log line. A related rule: a flag that the SDK owns (“an ad is showing”) may only be cleared by the SDK’s callback or by a timeout, never by the app resuming. On resume the ad is often still alive.

What I did and did not check

I read the project’s rules and the code references they cite. The Android timer behaviour is quoted from those notes, which attribute it to JavaTimerManager.onHostPause. I did not reproduce it with a new test build while writing this, and I have not measured how the numbers (the 4, 8 and 240 second values) behave in your app. Tune them on a real device with a release build. A passing unit test does not show that the ad flow is quick enough.