When the app is sitting in the background for a while and the OS closes the app, or when changing permissions in the Settings app, like flipping on and off the Storage permissions that will cause the app to relaunch we can observe how SplashActivity is started and the JS context is initialized and executed but right after we call startSingleScreenApp
which creates the NavigationActivity this piece of code runs
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!NavigationApplication.instance.getReactGateway().hasStartedCreatingContext() ||
getIntent() == null ||
getIntent().getBundleExtra("ACTIVITY_PARAMS_BUNDLE") == null) {
SplashActivity.start(this);
finish();
return;
}
activityParams = NavigationCommandsHandler.parseActivityParams(getIntent());
disableActivityShowAnimationIfNeeded();
setOrientation();
createModalController();
createLayout();
NavigationApplication.instance.getActivityCallbacks().onActivityCreated(this, savedInstanceState);
}
Somehow NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()
is false at this moment in time so the SplashScreen is invoked again, entering in an infinite loop where only the Splash Screen is being shown.
I don't understand much of the code, so I haven't been able to come up with a solution.
And the JS code does include
Promise.resolve(Navigation.isAppLaunched()).then((appLaunched) => {
if (this.startAppFromPushNotification) {
return;
}
if (appLaunched) {
this.launchApp(); // App is launched -> show UI
} else {
new NativeEventsReceiver().appLaunched(this.launchApp); // App hasn't been launched yet -> show the UI only when needed.
}
});
The weird thing is that if during the loop I send the app to the background while in the loop this code gets called new NativeEventsReceiver().appLaunched(this.launchApp);
and when bringing the app to the background it starts to work just fine.
I am having the same issue, when the OS kills the app due to low memory or running too long in the background.
I am able to reproduce it by just enabling on my phone settings Don't keep activities, so that every time I dismiss the app with the home button, the OS kills it.
Next time I open it up again, the Splash Screen hangs forever (or that's the illusion, although as @enahum pointed out it seems to be an infinite loop).
Curiously, when that happens, if I put the application on _pause_ state, by pressing the squared button on the hardware bottom bar (to see all the active applications) and select it back again, the loop breaks and the main activity will be finally launched.
I've been also debugging this for hours today thinking it was something on my JS code, but I run out of ideas.
Environment
I fixed by applying this solution:
https://github.com/wix/react-native-navigation/issues/1022#issuecomment-329432373
@rauliyohmc you are a godsend my friend, that seems to have solved the issue, will report back if it does not solve it completely, but so far so good
Looks like when exiting the app with the back button the splash screen still stays forever.
I have the same issue and tried (i think so ^^) all the solutions mentioned here in the issues.
So to get it to work I set removed the clearHostOnActivityDestroy
overwrite and forced the App to shutdown completely if BackButton is pressed:
(NavigationActivity, LL 203++)
@Override
public void onBackPressed() {
if (layout != null && layout.handleBackInJs()) {
return;
}
finish();
System.exit(0);
}
So no Idea if this has any (bad) side-effects, but at least I can quit the App and restart it.
@rauliyohmc You are really a godsend my friend, this's just killing me half a day
@enahum Were you able to solve this? I tried the solution that @rauliyohmc refers to - but the problem with it is that if I press "back" from the root to leave the app and then go back into the app it is again in this splash screen state.
@noambonnie I ended up running this before building the android app
sed -i'' -e "s|super.onBackPressed();|this.moveTaskToBack(true);|g" node_modules/react-native-navigation/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java
basically is replacing the behavior of the back button where instead of closing the app it moves it to the background
Sigh... Was there any acknowledgement from @guyca that this is a bug that would be fixed? I'm a bit reluctant to go change library code.
Has it been working with no side effects for you, @enahum ?
Yup no side effects at all
@enahum can I bug you with a few more questions?
I'm struggling to get it all to work...
"react-native": "0.55.3"
"react-native-navigation": "^1.1.446"
It is still the issue.
Same here, on Android the Splash screen freezes. Fixes provided in here #1022 (comment) does not work.
Fixing the behaviour of the back button is not fixing the root problem, its a bubblegum fix. The real issue is when the system kills the app in the background which then causes the freeze in the Splash screen. As an end user, I see that the app just crashes from time to time. Having just a couple of hundred educated users that's fine, but with thousands of users, this is becomes a critical bug.
Wix team, I hope you can find time to help us out on this problem.
"react-native-navigation": "^1.1.440",
"react-native": "^0.51.0",
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.
Hi ! I'm still getting this issue even by overriding clearHostOnActivityDestroy (). Has someone found another fix for this bug ?
Dependencies :
"react": "16.0.0-alpha.6",
"react-native": "0.43.3",
"react-native-navigation": "1.1.398",
Ok so i downgraded my version of react-native-navigation to "1.1.250" and everything seems to work fine and i can't reproduce the issue anymore.
I have made an attempt to fix this in https://github.com/wix/react-native-navigation/pull/3688. I'll be running more tests to verify this later.
I'm seeing this too. Anyone know if its fixed in 2.0?
Still seeing this issue with react-native: 0.55.4
and react-native-navigation: ^1.1.463
Try 1.1.485. I think some changes went in recently that fixed it for me.
@stevesouth thanks, I just tried that, but still no luck. Which version of RN are you using? Also it seems to be fixed in V2 from what I've tried, but unfortunately implementing that will take some time for our team.
Most helpful comment
Same here, on Android the Splash screen freezes. Fixes provided in here #1022 (comment) does not work.
Fixing the behaviour of the back button is not fixing the root problem, its a bubblegum fix. The real issue is when the system kills the app in the background which then causes the freeze in the Splash screen. As an end user, I see that the app just crashes from time to time. Having just a couple of hundred educated users that's fine, but with thousands of users, this is becomes a critical bug.
Wix team, I hope you can find time to help us out on this problem.
"react-native-navigation": "^1.1.440",
"react-native": "^0.51.0",