Issue: RN | - android 백 버튼으로 앱 종료 시 백그라운드 실행되는 이슈

Lumpen·2023년 3월 16일
0

ReactNative

목록 보기
11/42

android 에서 백버튼으로 앱 종료를 구현했는데
종료되지 않고 백그라운드에서 계속 실행중인 이슈가 있었다

BackHandler.exitApp()이후에
return true 를 주어 해결

https://stackoverflow.com/questions/52255920/react-native-android-backhandler-exit-app

const backAction = () => {
    Alert.alert('app exit', '정말 앱을 종료하시겠습니까?', [
      {
        text: '취소',
        onPress: () => null,
        style: 'cancel',
      },
      {
        text: '확인',
        onPress: () => {
          BackHandler.exitApp();
          return true;
        },
      },
    ]);
    return true;
  };


React.useEffect(() => {
    const backHandler = BackHandler.addEventListener(
      'hardwareBackPress',
      backAction,
    );

    return () => backHandler.remove();
  }, []);
profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글