react-native: [Android][0.22.2] Possible Unhandled Promise Rejection after reopening app from minimized/background state

React Native Version: 0.22.2 Platform: Android System: Ubuntu 15.04 Device: Samsung Note 3 (5.0)

Hi guys, after upgrading from 0.21 to 0.22.2, I’m experiencing the warning below every time I reopen my app from minimized/background state.

‘Possible Unhandled Promise Rejection (id: 0): Tried to change the status bar while not attached to an Activity’

But when I remove the StatusBar component from my view, the warning goes away (obviously).

This is my snippet:

<View style={ {flex: 1, backgroundColor: 'white'} }>
<StatusBar
  backgroundColor={this.props.statusbarBGColor}
          barStyle={"light-content"}
         />
        {toolbar}
    <View style={[styles.container, this.props.overrideStyle]}>
        {this.props.children}
    </View>            
</View>

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 12
  • Comments: 26 (6 by maintainers)

Most upvoted comments

+1RN.0.34.0

#10421 should fix this, the warning will be moved to a native log.

It seems that componentDidMount of the main component may happen before react-native is attached to an activity.

class RNTest extends Component {
  componentDidMount() {
    StatusBar.setHidden(true);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
      </View>
    );
  }
}

// ...

AppRegistry.registerComponent('RNTest', () => RNTest);

screenshot_2016-08-23-19-31-11_com rntest

I am having the same issue, but for me it happens only on device, not on emulator (I am using the new standard emulator from build tools 25.1.1 rather than GenyMotion emulator, so that may be related). Whenever I make a change in my editor and cause a Hot Reload on device (Samsung Galaxy S7, haven’t tested on other devices yet), I get the Promise Rejection warning. Output from logcat is:

04-11 16:28:56.384  1175  1507 I ReactNativeJS: [React Transform HMR] Patching ReactTest
04-11 16:28:56.504  1175  1507 W ReactNativeJS: Possible Unhandled Promise Rejection (id: 7):
04-11 16:28:56.504  1175  1507 W ReactNativeJS: Network request failed
04-11 16:28:56.504  1175  1507 W ReactNativeJS: onload@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14486:21
04-11 16:28:56.504  1175  1507 W ReactNativeJS: _sendLoad@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14079:7
04-11 16:28:56.504  1175  1507 W ReactNativeJS: setReadyState@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:14069:15
04-11 16:28:56.504  1175  1507 W ReactNativeJS: _didCompleteResponse@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:13964:19
04-11 16:28:56.504  1175  1507 W ReactNativeJS: call@[native code]
04-11 16:28:56.504  1175  1507 W ReactNativeJS: http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:13902:110
04-11 16:28:56.504  1175  1507 W ReactNativeJS: emit@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:9481:28
04-11 16:28:56.504  1175  1507 W ReactNativeJS: __callFunction@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7817:28
04-11 16:28:56.504  1175  1507 W ReactNativeJS: http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7721:22
04-11 16:28:56.504  1175  1507 W ReactNativeJS: guard@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7675:3
04-11 16:28:56.504  1175  1507 W ReactNativeJS: callFunctionReturnFlushedQueue@http://10.20.45.97:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:7720:6
04-11 16:28:56.504  1175  1507 W ReactNativeJS: callFunctionReturnFlushedQueue@[native code]
04-11 16:28:56.504  1175  1507 W ReactNativeJS: global code

+1 RN 0.37

+1 RN 0.38

I don’t get the orange error message, but my translucent status bar loses all of it’s styling. I’m using the component rather than the API.

This issue only occurs sometimes, specifically when:

  • Bringing the app back from the background
  • Opening the app from a push notification

+1 RN 0.38

Getting this with RN 0.37 (Android, Windows) on emulator (have not tried an actual device) when I return to the app from a background state, but only when I exit the app with the Android hardware back button.

All I’m doing is:

<StatusBar
    backgroundColor='#FF8B8B'
    barStyle='light-content'
/>

and:

componentDidMount() {
    AppState.addEventListener('change', this._handleAppState);
}

componentWillUnmount() {
    AppState.removeEventListener('change', this._handleAppState);
}

_handleAppState(appState) {
    console.log('Application state change: '+appState);
}

Fresh 0.36 too. Is it possible that it is related to router-flux somehow? Or you don’t use it?

I think this happens methods on statusbar before react-native is attached to an activity. The best way to avoid this is either to use the component or call methods in componentDidMount of your main component.

We should probably improve the error message to make this less confusing and maybe catch the promise to avoid the unhandled promise rejection.

This also happens to me and when I reopen the app the status bar is permanently hidden 😕

+1 RN 0.36.1

Do you use AppState and setState when the app state changes?

Also the warning should not happen in 0.23.0-rc1 as I’ve changed the implementation to be smarter and not update the status bar values if they didn’t change.

Is there anything which re-renders the component in which you’ve the statusbar? e.g. - some event which updates state in parent component.

cc @janicduplessis