React-native: [Android] AppState 'inactive' not triggered on Android

Created on 15 Jun 2017  路  13Comments  路  Source: facebook/react-native

Description

When listening to an AppState change, inactive is never triggered on Android, only background.

Reproduction Steps

  1. Setup a change listener on AppState.
  2. Output the current app state in the listener function.
  3. Send the app to the background (go to home screen) and notice background is logged, but never inactive

Sample Code

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

_handleAppStateChange(currentAppState) {
  console.log(currentAppState); // never outputs 'inactive' on android
}

Additional Information

  • React Native version: 0.43.3
  • Platform: Android
  • Development Operating System: macOS
  • Testing on: Android Simulator with a Nexus 5 with Nougat
Stale

Most helpful comment

I'm not aware that the issue is solved. It would be required to take action when the app goes into background, e.g. covering the app's screen for privacy reasons, so that the system's screenshot in the app-switch does not show the content of the app, but it's lock screen.

All 13 comments

+1 RN 0.44.0, 0.45.1

+1

+1 RN 0.45.1

+1

+1 RN 0.42.0

+1. The inactive state is not sent when receiving a phone call aswell.

Edit: Have a look at AppStateModule. It seems that there are only three states possible: uninitalized, foreground and background. Correct me if I'm wrong, but I don't think that Android has the inactive state, so that would explain why it was not implemented on Android. It would be a good thing to mention in the docs.

@JLWalsh, according to https://stackoverflow.com/a/41009169/3102305, there seems to be an inactive (onPause) event/state.

Hope that helps.

Our issue is, that we want to re-render the main component for privacy reasons as the screenshot of the app that is used in the task list should only show a "covered" version, not the apps last screen.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

I'm not aware that the issue is solved. It would be required to take action when the app goes into background, e.g. covering the app's screen for privacy reasons, so that the system's screenshot in the app-switch does not show the content of the app, but it's lock screen.

Did you find a solution for the described case? @martin-rueegg ?

We need it for the same scenario. Rendering a view before the Snapshot for Task Switcher is made (Android). On iOS it works just fine.

I also discover that when detecting NFC, it will also trigger background and then active.

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

jlongster picture jlongster  路  3Comments

lazywei picture lazywei  路  3Comments

grabbou picture grabbou  路  3Comments

janmonschke picture janmonschke  路  3Comments