React-native-mapbox-gl: [Android] GPS is left on even if app is switced to background

Created on 26 Oct 2017  路  11Comments  路  Source: nitaliano/react-native-mapbox-gl

I have mapview with showsUserLocation set to true. If app is switched to background the gps is still left on and it is draining my battery.

I also tried to set showsUserLocation to false on app state change, but that does not have any affect.

In using mapbox ver 5.2.3-alpha1

There is similar issue #310, which is closed already, but it looks like this is still reproducing. Do you have any ideas @nitaliano ?

Update 1.11.2017
Im able to reproduce this on 6.0.0-beta1. If I set followMode: MapboxGL.UserTrackingModes.Follow or showUserLocation: true and switch app to background gps is still left on. I think the map view should handle it's own state itself, with out needing developer to explicitly set follow mode to none etc (which is not completely working too) when app is in background.

I also tried to update followMode and showUserLocation based on app state changes, im able to switch off gps, but when I resume the app gps is not set on again .

  handleAppStateChange = (nextAppState) => {
    if (nextAppState === 'active') {
      this.setState({
        followMode: MapboxGL.UserTrackingModes.Follow,
        showUserLocation: true,
      });
    } else if (nextAppState.match(/inactive|background/)) {
      this.setState({
        followMode: MapboxGL.UserTrackingModes.None,
        showUserLocation: false

      });
    }
  };

  render() {
    return (
      <View style={styles.container}>
        <MapboxGL.MapView
            style={styles.map}
        showUserLocation={this.state.showUserLocation}
            userTrackingMode={this.state.followMode} /> 
      </View>
    );
  }
}

I think this is quite critical issue and makes the map basically unusable on android. I do not want to build app which drains users battery when the app is in background 馃槥

Most helpful comment

@hannta I know what's happening we just need to hook into the Android Activities lifecycle events and we'll have access to onResume onPause and onDestroy. I'll have a PR out this week for v6 to address it

All 11 comments

Yeah this is draining lot of battery :(

@hannta try setting your userTrackingMode to none

@nitaliano I think that is what @hannta tried already. I think he just made typo saying he set it to false

@nitaliano Yep, that is what im basically doing. Im setting userTrackingMode to none and showsUserLocation to false. But that has no affect, gps still on.

Also if I do not use userTrackingMode at all, issue is still there if I have showsUserLocation set to true. And things are not changing if I set showsUserLocation to false when app goes to background.

@henrikra I think you mixed up userTrackingMode and showsUserLocation 馃檪. showsUserLocation is boolean.

@nitaliano Can you confirm that this is happening?

I added some more findings on v6 to issue itself. So the issue is still there in v6.

@hannta I know what's happening we just need to hook into the Android Activities lifecycle events and we'll have access to onResume onPause and onDestroy. I'll have a PR out this week for v6 to address it

Ok, thanks @nitaliano Cant wait to test this out!

I added the lifecycle events to this PR https://github.com/mapbox/react-native-mapbox-gl/pull/705.

Closing this out as the fix has been merged if you're still seeing this please reopen

I am still seeing this behaviour. I opened a new bug here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Amalp picture Amalp  路  3Comments

digitaldavenyc picture digitaldavenyc  路  4Comments

alexisohayon picture alexisohayon  路  4Comments

madroneropaulo picture madroneropaulo  路  4Comments

max-prokopenko picture max-prokopenko  路  4Comments