jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.1k stars 110 forks source link

Problem in background task with minimize-maximize app #32

Open ViktoriaShelestenko opened 6 years ago

ViktoriaShelestenko commented 6 years ago

Hello. I found problem in your module. I have app, when i minimize it or close it on android all works fine. But when i have these steps:

background task does not work. Help me please, what i can do with that ?

ViktoriaShelestenko commented 6 years ago

I have solve! If someone have the same problem as me, use AppState

AppState.addEventListener('change', this._handleAppStateChange);

 _handleAppStateChange = (nextAppState) => {
        if (this.state.appState && this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
            BackgroundTask.schedule();
        }
        this.setState({appState: nextAppState});
    }

https://facebook.github.io/react-native/docs/appstate.html