React-native-router-flux: How to quit Android App?I used BackHandler

Created on 13 Sep 2017  Â·  5Comments  Â·  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux ^4.0.0-beta.21 (v3 is not supported)
  • react-native v0.48.0

Expected behaviour

Exit App

Actual behaviour

Use BackHandler after crashing

Steps to reproduce

1.

const reducerCreate = params => {
    const defaultReducer = new Reducer(params);
    return (state, action) => {
        console.log('ACTION:',action)

        if(action.type === 'Navigation/BACK'){
            console.log('退出APP');
            BackHandler.exitApp();
        }
    return defaultReducer(state, action);
}

2.Error: Cannot read property 'startsWith' of undefined

handleException @ index.android.bundle:11796
handleError @ index.android.bundle:12611
reportFatalError @ index.android.bundle:685
__guard @ index.android.bundle:2064
callFunctionReturnFlushedQueue @ index.android.bundle:1947
(anonymous) @ debuggerWorker.js:71

3.
default

All 5 comments

You seem to call startsWith method on something that is undefined. I don't think backHandler is responsible for this error. Could you check if error is not occuring elsewhere ?

You can try to override BackHandler from react native in root component

`componentDidMount(){
BackHandler.addEventListener('hardwareBackPress', BackHandler.exitApp)
}

componentWillUnmount(){
BackHandler.removeEventListener('hardwareBackPress', BackHandler.exitApp)
}'

I'm add the code in the Example , Did not do anything else @vhoen

@ynsgnr I was in the Example Launch to add your code, click the Android return button can not be used

this library has solved my issue
https://github.com/wumke/react-native-exit-app

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirankalyan5 picture kirankalyan5  Â·  3Comments

xnog picture xnog  Â·  3Comments

vinayr picture vinayr  Â·  3Comments

YouYII picture YouYII  Â·  3Comments

basdvries picture basdvries  Â·  3Comments