diff --git a/packages/expo-web-browser/src/WebBrowser.ts b/packages/expo-web-browser/src/WebBrowser.ts index 37ee736ffcb01..dc19bcc0d6660 100644 --- a/packages/expo-web-browser/src/WebBrowser.ts +++ b/packages/expo-web-browser/src/WebBrowser.ts @@ -149,7 +149,18 @@ let _redirectHandler: ((event: RedirectEvent) => void) | null = null; // returns to active let _onWebBrowserCloseAndroid: null | (() => void) = null; +// Store previous app state to check whether the listener has ever been attached +let _previousAppState: null | string = AppState.currentState; + function _onAppStateChangeAndroid(state: AppStateStatus) { + // if _previousAppState is null, we assume that the first call to + // AppState#change event is not actually triggered by a real change + // (https://facebook.github.io/react-native/docs/appstate#basic-usage) + if (_previousAppState === null) { + _previousAppState = state; + return; + } + if (state === 'active' && _onWebBrowserCloseAndroid) { _onWebBrowserCloseAndroid(); }