react native(expo) crashes when I close app on android background

Hi~ I made a simple hybrid app and it works well but when I close the app on android background(click hamburger icon and swipe the app to close), the app wont start. It just crash until reinstall. Google Play console, I cant see the error message as this

java.lang.RuntimeException

java.lang.RuntimeException: Expo encountered a fatal error: ReferenceError: Can't find variable: BackHandler
Q
  at host.exp.exponent.experience.f.o (BaseExperienceActivity.java:7)
  at host.exp.exponent.experience.a.run (Unknown Source:2)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7700)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:952)

and this is my app code

App.js

import React, { Component } from 'react';
import { BackHandler } from 'react-native';
import { WebView } from 'react-native-webview';
import { StatusBar } from "react-native";
import * as SplashScreen from 'expo-splash-screen';
import ProgressWebView from "react-native-progress-webview";

function sleep (ms) {
  return new Promise(
    resolve => setTimeout(resolve, ms)
  );
}

async function delay_splash() {
  await SplashScreen.preventAutoHideAsync();
  await sleep(3000);
  await SplashScreen.hideAsync();    
};

export default class WebViewMoviezSpace extends Component {
  constructor(props) {
    super(props);
    this.WEBVIEW_REF = React.createRef();
  }

  componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
  }

  componentWillUnmount() {
    BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
  }

  handleBackButton = ()=>{
    this.WEBVIEW_REF.current.goBack();
    return true;
  }

  onNavigationStateChange(navState) {
    this.setState({
      canGoBack: navState.canGoBack
    });
  }

  render(){
    delay_splash();
    return (
      <>
      <StatusBar backgroundColor="#F4F6FA" barStyle="dark-content" /> 
      <ProgressWebView
        source={{ uri: "http://34.64.168.91/" }}
        ref={this.WEBVIEW_REF}
        onNavigationStateChange={this.onNavigationStateChange.bind(this)}
      />
      </>
    )
  }
}

app.json

{
  "expo": {
    "name": "미스터스탁",
    "slug": "mrstock_app",
    "version": "1.0.2",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "primaryColor":"#f74172",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "cover",
      "backgroundColor": "#1f1f1f"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "ios": {
      "bundleIdentifier": "com.mrstock.mrstockapp",
      "buildNumber": "1.0.6",
      "supportsTablet": false,
      "config": {
        "usesNonExemptEncryption": false
      }

    },
    "android": {
      "package": "com.mrstock.mrstock",
      "versionCode": 5,
      "permissions": ["WRITE_SETTINGS"] 
    }
  }
}

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.