React-native-navigation: [Android] App stuck when resuming after being in the background for a long time

Created on 22 May 2018  路  4Comments  路  Source: wix/react-native-navigation

Issue Description

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.

Steps to Reproduce / Code Snippets / Screenshots

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.


Environment

  • React Native Navigation version: I've tested 1.1.348, 1.1.457 and 1.1.462, problem occurs on all these versions.
  • React Native version: I've tested 0.51.0, 0.55.3 and 0.55.4, same problem on all versions
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): The problems occur both on device (Samsung Galaxy S9+, Android version 8.0.0) and emulator (Android version 7.1.1), and both in debug and release versions of the app.

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 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.

All 4 comments

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)

Was this page helpful?
0 / 5 - 0 ratings