Our react-native 0.66 Android app has an AppState change
handler which is called when the app goes into the background / foreground...
import {AppState} from 'react-native';
...
this.changeUnsubscribe = AppState.addEventListener('change', this.handleChange)
...
handleChange(nextAppState) { console.log(`App state changed to: ${nextAppState}`) }
Works perfectly on Android 10. However on Android 12, the change event isn't happening when the user brings up the Task Manager.
Instead the event happens when you swipe up the app in the Task Manager (to close the app).
Unfortunately that causes a problem: It seems Android 12 limits the amount of activity you can perform as the app is closing. We're trying to save user data when the app goes into the background, and it's not always managing it. Pre-Android 12 our app managed it fine.
I can't find any mention of this new behaviour in the react-native or Android docs. Any tips anyone?
Answering my own question, hope it helps others:
For react-native v0.66 on Android 12 (may be the case for other versions): The system Task Manager no longer triggers the AppState change
event.
It now triggers an AppState blur
event. Returning to the app triggers a focus
event. The AppState currentState
will continue to be active
while Task Manager is in the foreground.