Is there any library which has ability like moveTaskToBack
in React Native?
Previously I use https://github.com/jaysoo/react-native-activity-android and it has moveTaskToBack
. But unfortunately this repo is not active anymore, and since React Native 0.29, it has some internal change which make that library didn't work.
I'm not sure it's what you need, but if you put this in your MainActivity.java class:
@Override
public void invokeDefaultOnBackPressed() {
// do not call super.invokeDefaultOnBackPressed() as it will close the app. Instead lets just put it in the background.
moveTaskToBack(true);
}
Then when user press the android back button on the "root" page, the app will go in background instead of being closed.
Source: background a react-native android app using back button
Use react-native-navigation, then navigate to your projects node modules folder and locate the react-native-navigation folder and inside it, follow the path to the NavigationActivity.java:
/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java.
In the NavigationActivity.java
file, you will see the following method at around line 196:
@Override
public void invokeDefaultOnBackPressed() {
if (layout != null && !layout.onBackPressed()) {
super.onBackPressed();
}
}
Comment out the line: super.onBackPressed()
and add the line: this.moveTaskToBack(true);
and thats all! Happy coding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With