Android app gets stuck on the splash screen after putting it in the background with the home button and then resuming it after several hours.
The problem is most easily reproduced this way:
Create a new app with react-native init app
and install react-native-navigation following the instructions at https://wix.github.io/react-native-navigation/#/installation-android
Implement a simple test app:
import React, { Component } from 'react';
import {
Text,
View
} from 'react-native';
import { Navigation } from 'react-native-navigation';
class TestScreen extends Component {
render() {
return (
<View>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
Navigation.registerComponent('testScreen', () => TestScreen);
Navigation.startSingleScreenApp({
screen: {
screen: 'testScreen',
title: 'Welcome',
},
animationType: 'slide-down'
});
Start the app with react-native run-android
. When the app has started shut it down and then start it again by pressing the launcher icon. Press the home button to put the app in the background and then wait several hours (it's difficult to make a good estimate unfortunately) and then resume the app, this will result in a permanent blank screen (or splash screen if such is implemented). Putting the app in the background and resuming it again solves the problem.
The "wait several hours" part makes it hard to debug, but I've also managed to recreate the error by starting the app and putting it in the background as described above and then going to Settings -> Developer Options -> Running services -> Show cached processes -> native-navigation-app-name -> Stop
and then resuming the app.
It is worth noting that resuming the app in any other situation than the two described above seems to work fine.
The issue is RNN-specific. I've tried running a non-RNN app and this problem does not occur.
I am also facing the same issue.
@barhbie You found any solutions?
Yes, I should've posted the solution and closed this issue but I forgot.
I applied the changes proposed by @guyca in https://github.com/wix/react-native-navigation/issues/1022#issuecomment-329432373 and it solved my problem.
Do note that there is a small error in his solution, where he states that you should override clearHostOnActivityDestroy
in MainApplication
like this:
@Override
public boolean clearHostOnActivityDestroy() {
return false;
}
However, as stated by @rcidt in https://github.com/wix/react-native-navigation/issues/1022#issuecomment-397374735 the superclass method has an argument application
which must be present in the overriding method as well, like so:
@Override
public boolean clearHostOnActivityDestroy(Activity activity) {
return false;
}
This also means you have to import android.app.Activity
in MainApplication
if you haven't already.
This worked for me and I hope it solves your problem as well.
Great, it worked for me
Thanks
I'm having this issue (js thread freezing when re-opening the app after a long time), though not using react-native-navigation - is it exclusive to the package, or a general issue RN has that can be solved with the clearHostOnActivityDestroy fix? (I received an error when trying the clearHostOnActivityDestroy fix just to see)
Most helpful comment
Yes, I should've posted the solution and closed this issue but I forgot.
I applied the changes proposed by @guyca in https://github.com/wix/react-native-navigation/issues/1022#issuecomment-329432373 and it solved my problem.
Do note that there is a small error in his solution, where he states that you should override
clearHostOnActivityDestroy
inMainApplication
like this:However, as stated by @rcidt in https://github.com/wix/react-native-navigation/issues/1022#issuecomment-397374735 the superclass method has an argument
application
which must be present in the overriding method as well, like so:This also means you have to import
android.app.Activity
inMainApplication
if you haven't already.This worked for me and I hope it solves your problem as well.