Skip to content

[Bug]: UserLocation stops updating after restarting app with background foregroundService on Android #3965

Closed as not planned

Description

@Slo1k

Mapbox Implementation

Mapbox GL

Mapbox Version

default

React Native Version

0.78.2

Platform

Android

@rnmapbox/maps version

10.1.42

Standalone component to reproduce

import React, {useState} from "react";
import MapboxGL, {Camera, MapView, UserLocation} from "@rnmapbox/maps";
import {ActivityIndicator, Platform, View} from "react-native";

Platform.OS === "android" && MapboxGL.requestAndroidLocationPermissions();

export const START_ZOOM_LEVEL = 15;
export const MAX_ZOOM_LEVEL = 18;
export const MIN_ZOOM_LEVEL = 1;

const DEFAULT_LOCATION = {
  latitude: 52.52,
  longitude: 13.405,
};

export default function AppMap() {
  const [mapLoaded, setMapLoaded] = useState(false);

  return (
    <View style={{flex: 1}}>
      {!mapLoaded && (
        <View
          style={{
            position: "absolute",
            zIndex: 200,
            bottom: "50%",
            alignSelf: "center",
          }}>
          <View
            style={{
              backgroundColor: "white",
              padding: 8,
              borderRadius: 9999,
            }}>
            <ActivityIndicator size={48} />
          </View>
        </View>
      )}

      <MapView
        logoEnabled={true}
        attributionEnabled={true}
        rotateEnabled={false}
        zoomEnabled
        scrollEnabled
        pitchEnabled={false}
        scaleBarEnabled={false}
        onDidFinishLoadingMap={() => {
          setMapLoaded(true);
        }}
        style={{flex: 1}}>
        <>
          <Camera
            minZoomLevel={MIN_ZOOM_LEVEL}
            maxZoomLevel={MAX_ZOOM_LEVEL}
            allowUpdates={true}
            animationMode="none"
            defaultSettings={{
              centerCoordinate: [
                DEFAULT_LOCATION.longitude,
                DEFAULT_LOCATION.latitude,
              ],
              zoomLevel: START_ZOOM_LEVEL,
            }}
          />

          <UserLocation
            androidRenderMode="normal"
            requestsAlwaysUse
            minDisplacement={10}
            visible={true}
            onUpdate={res => {
              console.log("User location updated:", res);
            }}
          />
        </>
      </MapView>
    </View>
  );
}

Observed behavior and steps to reproduce

Steps to reproduce

  1. Open the app and display the map with UserLocation.
  2. Start some kind of a android foregroundService that works even when the app is closed
  3. Restart the app.
  4. Observe that the user location updates only a couple of times and then stops.
  5. Switch to the deprecated renderMode={UserLocationRenderMode.Native} and notice that the location updates correctly, but onUpdate remains non-functional.

Expected behavior

The map should continuously update the user’s location while the foreground service is running, even after the app is restarted.

Notes / preliminary analysis

When I start a foregroundService with android:foregroundServiceType="location", my location on the map stops updating after restarting the app. The position is retrieved at most twice and then stops completely.

If I use the deprecated renderMode={UserLocationRenderMode.Native} in UserLocation, the location on the map updates correctly, but the onUpdate callback still doesn’t return anything.

It looks like the issue is related to the interaction between Mapbox and Android foreground services. From what I’ve tested, the specific type of foregroundService doesn’t seem to make a difference.

Additional links and references

No response

Activity

  1. added
    bug 🪲
    on Sep 5, 2025
  2. changed the title [-][Bug]: UserLocation stops updating after restarting app[/-] [+][Bug]: UserLocation stops updating after restarting app with background foregroundService on Android[/+] on Sep 5, 2025
  3. RyanTG commented on Sep 21, 2025

    @RyanTG
    Contributor

    Just curious: are you seeing this on Android 16 only, or all Android? Just asking because we’re experiencing an Android 16 issue where it works fine in initial start, but then the map spins if you close and re-open the app. Still diagnosing, but it sounds similar to yours.

  4. RyanTG commented on Sep 23, 2025

    @RyanTG
    Contributor

    The issue we experienced was solved here expo/expo#39851. It was an issue with Expo-Location, wherein requesting requestForegroundPermissionsAsync when that permission was already granted produced a problem. That issue has a workaround.

    Does this resolve your issue?

  5. mfazekas commented on Oct 18, 2025

    @mfazekas
    Contributor

    @Slo1k can you post a step by step instructions, to reproduce?

    Can you provide a concrete example for this:

    Start some kind of a android foregroundService that works even when the app is closed

    Also have to looked into this: #3965 (comment) ?

  6. mfazekas commented on Oct 12, 2026

    @mfazekas
    Contributor

    Closing as we haven't heard back. If this still happens on the latest release, please reopen with a standalone reproducer and the steps to trigger it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidNeeds: Author Feedbackbug 🪲

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions