How to keep React Native apps running when user minimum the app or screen off or open another app?

Viewed 1069

I am develop like running track app using react native

Here is my code

export default class App extends React.Component {  
    constructor(){  
        super();  
        this.state = {  
            where: {lat:null, lng:null},  
        }  
    }  
    checklocation(){        
        navigator.geolocation.getCurrentPosition(this.geoSuccess);  
    }  
 
    geoSuccess = (position) => {  
        this.setState({  
            ready:true,  
            where: {lat: position.coords.latitude,lng:position.coords.longitude }  
        })  
    } 
    start_timer(){
     setInterval(() => {
      this.checklocation();
     }, 1000);
    }
    render() { 
        return (  
            <View style={styles.container}>  
                   <Button onPress={this.start_timer()} title="Start Tracking" />
                    <Text style={styles.big}>  
                        Latitude: {'\n'}{this.state.where.lat}   
                        {'\n'}{'\n'}
                        Longitude: {'\n'}{this.state.where.lng}  
                    </Text>  
 
            </View>  
        );  
    }  
} 

But When the user minimum the app or screen off or open another app? The apps is not running.

I have tried to add

<uses-permission android:name="android.permission.WAKE_LOCK" />

to AndroidManifest.xml

but still not work, any idea how to keep React Native apps running when users minimum the app or screen off or open another app?

1 Answers
Related