question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Back button will not send the app to the background

See original GitHub issue

Version

Tell us which versions you are using:

  • react-native-router-flux 4.0.0-beta.40
  • react-native 0.55.4

Expected behaviour

If you are navigating inside the app, after pressing multiple times back button on android, the app should be sent to the background the same way when you press the menu button

Actual behaviour

After pressing back button the app will come back to the initial screen (correct), but then it stays on the screen no matter how many times you press back button.

Just before this library was updated I had an issue where the back button would kill the app, so I fixed it and it was working perfectly. After updating flux to 4.0.0-beta.40 I have this issue .

Keep in mind that the scene structure did not change at all from what it was in the previous version

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
howieyoungcommented, Dec 8, 2018

Same issue with “react-native-router-flux”: “^4.0.6” However, I fixed it after I tried to set the backHandler to false manually:

       <Router
        sceneStyle={{ backgroundColor: '#fff' }}
        /*
        backAndroidHandler return true to stay in the app and return false to exit the app.
        Default handler will pop a scene and exit the app at last when the back key is pressed on Android.
        */
        backAndroidHandler={() => (false)}
      >

I wish that’s something helpful for you guys.

2reactions
howieyoungcommented, Jul 25, 2019

@wmonecke Hopefully you’ve resolved the problem already. But if you haven’t, you can do something like this.

import { ..., BackHandler } from 'react-native';

class App extends Component {
componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
}

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

onBackPress = () => {
    if (Actions.state.index === 0) {
      return false
    }
    Actions.pop();
    return true
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android back button not working as intended after background
Please try removing the attribute android:launchMode="singleInstance" in your activities, and check if it works.
Read more >
How to Fix Home Button/Back Button is not Working on Android?
How to Fix Home Button/ Back Button is not Working on Android?Step 1: Open "Play Store" App.Step 2: Do a search for "Navigation...
Read more >
How to Fix App Not Close When Press Back Button in Android
Some app will not close properly when you press back button in android devices, it will run in background and slow down your...
Read more >
Back Button/Gesture does not close apps anymore - Reddit
I'm on SPB2. 210513.011 (Pixel 4a 5G) and the back Gesture does not close ("onDestroy") apps anymore. Same with the back button, if...
Read more >
Provide custom back navigation - Android Developers
All Android devices provide a Back button for this type of navigation, so you should not add a Back button to your app's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found