Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to quit Android App?I used BackHandler #2383

Closed
CodeRabbitYu opened this issue Sep 13, 2017 · 5 comments
Closed

How to quit Android App?I used BackHandler #2383

CodeRabbitYu opened this issue Sep 13, 2017 · 5 comments

Comments

@CodeRabbitYu
Copy link

CodeRabbitYu commented Sep 13, 2017

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

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

default

@CodeRabbitYu CodeRabbitYu changed the title How to quit Andrews App?I used BackHandler How to quit Android App?I used BackHandler Sep 13, 2017
@vhoen
Copy link

vhoen commented Sep 13, 2017

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 ?

@ynsgnr
Copy link

ynsgnr commented Sep 13, 2017

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

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

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

@CodeRabbitYu
Copy link
Author

CodeRabbitYu commented Sep 14, 2017

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

@CodeRabbitYu
Copy link
Author

CodeRabbitYu commented Sep 14, 2017

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

@alizafardev
Copy link

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

@onrige onrige closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants