question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] AppState 'inactive' not triggered on Android

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

12reactions
martin-rueeggcommented, Dec 3, 2017

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.

3reactions
JLWalshcommented, Aug 8, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native AppState has no 'inactive' state on Android
Its not a bug. Android implementation of AppState component has only 'active' and 'background' state. Just curious, why do you want to show...
Read more >
AppState - React Native
[iOS] inactive - This is a state that occurs when transitioning between foreground & background, and during periods of inactivity such as ...
Read more >
Activity state changes - Android Developers
Different events, some user-triggered and some system-triggered, can cause an Activity to transition from one state to another.
Read more >
React Native AppState - Active | Background | Inactive
background – The app is running in the background. The user is either: using another app; on the home screen; [Android] on another...
Read more >
Using AppState in React Native to improve performance
The above states are given on both Android and iOS, but iOS supports an additional AppState called inactive , which occurs when the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found