LocationManager will not go away because itself is used by FusedLocationProvider. It really depends on your use case. For most apps Fused is great. But it you want really precise location you actually should use both and select which result looks best. Fused is good when you a need a location fix immediately, before you get a fix from satellites, but it can also fail in some special cases, like underground. Answer from gold_rush_doom on reddit.com
๐ŸŒ
Google
developers.google.com โ€บ google play services โ€บ fusedlocationproviderclient
FusedLocationProviderClient | Google Play services | Google for Developers
October 31, 2024 - FusedLocationProviderClient is the main entry point for interacting with the Fused Location Provider (FLP) and requires either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
Discussions

FusedLocationProviderClient vs LocationManager - What to use? Possible deprecation?
LocationManager will not go away because itself is used by FusedLocationProvider. It really depends on your use case. For most apps Fused is great. But it you want really precise location you actually should use both and select which result looks best. Fused is good when you a need a location fix immediately, before you get a fix from satellites, but it can also fail in some special cases, like underground. More on reddit.com
๐ŸŒ r/androiddev
7
5
May 2, 2023
Android FusedLocationProviderClient use across Activities - Stack Overflow
I am starting location updates in one activity and stopping them in a subsequent activity in the flow of my app. I create a final LocationUtilities class [code shown below with relevant parts] with More on stackoverflow.com
๐ŸŒ stackoverflow.com
android - FusedLocationProviderClient when and how to stop Looper? - Stack Overflow
I used to use FusedLocationApi until I learned that it is deprecated (see references below). It was simple to implement. As the documentation says you need to use it in conjunction with GoogleApiCl... More on stackoverflow.com
๐ŸŒ stackoverflow.com
android - How to get location using "fusedLocationClient.getCurrentLocation" method in Kotlin? - Stack Overflow
0 Android Kotlin - Strange behaviour getting location using fusedLocationProviderClient.getCurrentLocation More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @myofficework000 โ€บ real-time-location-tracking-made-easy-with-fused-location-provider-43de6437fbd3
Real-Time Location Tracking Made Easy with Fused Location Provider | by Abhishek Pathak | Medium
October 15, 2024 - <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> In the main activity, we first initialize the FusedLocationProviderClient to get access to location services.
๐ŸŒ
Reddit
reddit.com โ€บ r/androiddev โ€บ fusedlocationproviderclient vs locationmanager - what to use? possible deprecation?
r/androiddev on Reddit: FusedLocationProviderClient vs LocationManager - What to use? Possible deprecation?
May 2, 2023 -

We are currently working on an App that does a lot with users' locations. Therefore we are evaluating FusedLocationProviderClient and the "old" LocationManager to access the user's location over a long period of time.

The accuracy of the location is extremely important and we want to get the maximum out of the device. Initial testing showed great results with the "new" fused location provider. However, on some devices, this client is not available and in very rare cases the locations get really inaccurate after some time (<10min).

For some devices/cases we are thinking of using the "old" LocationManager, but my question is if this LocationManager will stick around in the future. I did some research but I wasn't able to find a lot of details. Google just "highly recommends switching to FusedLocationProviderClient", but it's missing some features of the LocationManager such as providing GNSS information.

Is it a good idea to use LocationManager and all the information that it provides such as GNSS Info?

Maybe some of you also did some research on this topic and can share the results.

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68198346 โ€บ android-fusedlocationproviderclient-use-across-activities
Android FusedLocationProviderClient use across Activities - Stack Overflow
And there seem to be complexities with stopping/unbinding from a foreground service that I am struggling with currently, from different activities. That's another post. From further testing, there appear to be NO ISSUES with using different instances of a fusedLocationProviderClient to start/stop updates; and there appear to be no issues with using a different Context in both cases.
Find elsewhere
๐ŸŒ
Android Developers
developer.android.com โ€บ core areas โ€บ sensors and location โ€บ request location updates
Request location updates | Sensors and location | Android Developers
This document explains how to request regular updates about a device's location using the Fused Location Provider's requestLocationUpdates() method in Android.
๐ŸŒ
Google
developers.google.com โ€บ location-context โ€บ fused-location-provider
Fused Location Provider API | Google for Developers
Get an overview of this battery-efficient location API and links to guides about how to use it.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ kotlin โ€บ using-fused-location-api-to-fetch-current-location-in-android
Using Fused Location API to Fetch Current Location in Android - GeeksforGeeks
July 23, 2025 - private fun setLocationListner() { val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) // for getting the current location update after every 2 seconds with high accuracy val locationRequest = LocationRequest().setInterval(2000).setFastestInterval(2000) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) fusedLocationProviderClient.requestLocationUpdates( locationRequest, object : LocationCallback() { override fun onLocationResult(locationResult: LocationResult) { super.onLocationResult(locationResult) for (location in locationResult.locations) { longPlaceholder.text = location.latitude.toString() latPlaceholder.text = location.longitude.toString() } // Things don't end here // You may also update the location on your web app } }, Looper.gfgLooper() ) } Finally, add the callback for the permissions request result: Kotlin ยท
Top answer
1 of 2
36

You just need to call mFusedLocationClient.removeLocationUpdates(mLocationCallback) in onPause() of your Activity. However, there is a bit more to it than just that.

Use member variables for the FusedLocationProviderClient and LocationRequest in your main activity:

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;

public class MainActivity extends AppCompatActivity
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

    FusedLocationProviderClient mFusedLocationClient;
    LocationRequest mLocationRequest;

    //..........

Use a member variable for the LocationCallback as well:

LocationCallback mLocationCallback = new LocationCallback(){
    @Override
    public void onLocationResult(LocationResult locationResult) {
        for (Location location : locationResult.getLocations()) {
            Log.i("MainActivity", "Location: " + location.getLatitude() + " " + location.getLongitude());

        }
    };

};

Then, assign mFusedLocationClient in onCreate() :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    requestLocationUpdates();

    //...............
}

Then in onResume(), if theFusedLocationProviderClient is set up, then use it.

@Override
public void onResume() {
    if (mFusedLocationClient != null) {
        requestLocationUpdates();
    }
}

public void requestLocationUpdates() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(120000); // two minute interval
    mLocationRequest.setFastestInterval(120000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
    }
}

And finally, in onPause(), call removeLocationUpdates():

@Override
public void onPause() {
    super.onPause();
    if (mFusedLocationClient != null) {
        mFusedLocationClient.removeLocationUpdates(mLocationCallback);
    }
}
2 of 2
1

After getting location just remove mFusedLocationClient.removeLocationUpdates as he mentioned in above answers.

if (mFusedLocationClient != null) 
        mFusedLocationClient.removeLocationUpdates(mLocationCallback);

Looper will be called requestLocationUpdates until you remove it.

In my problem, I did as I mention above. Below is my code.

  mFusedLocationClient.getLastLocation()
                    .addOnSuccessListener(new OnSuccessListener<Location>() {
                        @Override
                        public void onSuccess(Location location) {
                            // GPS location can be null if GPS is switched off
                            if (location != null) {

                                mLocation = location;

                                if (mFusedLocationClient != null) {
                                    mFusedLocationClient.removeLocationUpdates(mLocationCallback);
                                }
                          } else {
                                startLocationUpdates();
                           }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(HomeActivity.this, "Error trying to get last GPS location", Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        }
                    });

and below is my requestLocationUpdates so I will get a request until the location is available.

private void startLocationUpdates() {
        mSettingsClient.checkLocationSettings(mLocationSettingsRequest)
                .addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
                    @Override
                    public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
                        Log.i(TAG, "All location settings are satisfied.");

                        getPackageManager().checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, getPackageName());
                        mFusedLocationClient.requestLocationUpdates(mLocationRequest,
                                mLocationCallback, Looper.myLooper());
                        getLastLocationNewMethod();
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        int statusCode = ((ApiException) e).getStatusCode();
                        switch (statusCode) {
                            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                                Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade " +
                                        "location settings ");
                                try {
                                    ResolvableApiException rae = (ResolvableApiException) e;
                                    rae.startResolutionForResult(HomeActivity.this, 0x1);
                                } catch (IntentSender.SendIntentException sie) {
                                    Log.i(TAG, "PendingIntent unable to execute request.");
                                }
                                break;
                            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                                String errorMessage = "Location settings are inadequate, and cannot be " +
                                        "fixed here. Fix in Settings.";
                                Log.e(TAG, errorMessage);
                                Toast.makeText(HomeActivity.this, errorMessage, Toast.LENGTH_LONG).show();
                                //  mRequestingLocationUpdates = false;
                        }
                        getLastLocationNewMethod();  // this method is where I can get location. It is calling above method. 
                    }
                });
    }

Note: For more information here is GitHub Repo LINK

๐ŸŒ
Quora
quora.com โ€บ What-is-FusedLocationProviderClient-in-Android
What is FusedLocationProviderClient in Android? - Quora
Answer (1 of 2): Fused Location is actually a location service which combines GPS location and network location to achieve balance between battery consumption and accuracy. It's just a upgraded type of service which reduces battery usage and ...
Top answer
1 of 3
16

According to the documentation, the getCurrentLocation() takes two parameters.

The 1st parameter it takes is the priority (e.g. PRIORITY_HIGH_ACCURACY) to request the most accurate locations available, or any other priority that can be found here.

The 2nd parameter it takes is a cancellation token that can be used to cancel the current location request.

From the Google play services reference, a CancellationToken can only be created by creating a new instance of CancellationTokenSource.

so here is the code you need to use when using getCurrentLocation()

class YourActivity : AppCompatActivity() {

    private lateinit var fusedLocationClient: FusedLocationProviderClient

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.your_layout)

        fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

        fusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY, object : CancellationToken() {
                override fun onCanceledRequested(p0: OnTokenCanceledListener) = CancellationTokenSource().token

                override fun isCancellationRequested() = false
            })
            .addOnSuccessListener { location: Location? ->
                if (location == null)
                    Toast.makeText(this, "Cannot get location.", Toast.LENGTH_SHORT).show()
                else {
                    val lat = location.latitude
                    val lon = location.longitude
                }

            }

    }
}
2 of 3
4

I know the question is about Kotlin but I want to add for those searching for Java, based on this example in the documentation:

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
fusedLocationClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, cancellationTokenSource.getToken())
.addOnSuccessListener(MyActivity.this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
        // Got last known location. In some rare situations this can be null.
        if (location != null) {
            //do your thing
        }
        Log.w(TAG, "No current location could be found");
    }
});
Top answer
1 of 2
3

Instead of getting the last known location, you can get location updates in specific intervals. Here is the code.

Declare these fused location provider class and location callback class

private var mFusedLocationProviderClient: FusedLocationProviderClient? = null
private var mLocationRequest: LocationRequest? = null
private var mLocationCallback: LocationCallback? = null  
private const val LOCATION_REQUEST_INTERVAL: Long = 5000

`

Here is the necessary method for the location request

private fun createLocationRequest() {
    mLocationRequest = LocationRequest.create()
    mLocationRequest!!.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
    mLocationRequest!!.setInterval(LOCATION_REQUEST_INTERVAL).fastestInterval =
    LOCATION_REQUEST_INTERVAL
    requestLocationUpdate()
}

private fun requestLocationUpdate() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED ) {

        Log.e("permission", "denied");


        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return
    }

    mFusedLocationProviderClient!!.requestLocationUpdates(
        mLocationRequest,
        mLocationCallback,
        Looper.myLooper()
    )
}

Then call these "createLocationRequest" method and location callback classs in onCreate().

    mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(requireContext())

 createLocationRequest()
 mLocationCallback = object : LocationCallback() {

        override fun onLocationResult(locationResult: LocationResult) {
            super.onLocationResult(locationResult)
             val lat  = locationResult.lastLocation.latitude
             val lng = locationResult.lastLocation.longitude
                                
     
        }
    }

And remove location update listener in onPause() or onDestory() as per your requirement.

    mFusedLocationProviderClient!!.removeLocationUpdates(mLocationCallback)
2 of 2
0

Scenario 1:After gets message that location is disabled and exits.kill the app from recent app tray now Enable location . Then open App from Home page as new Activity now it should update location. if it's working,nothing wrong in App.App is working properly.

Scenario 2:If you have fusedLocation.getLastLocation() in onCreate() method,move that code to onResume() method.because when you open the App from recent apps tray ,onStart() method will invoked first then onResume() not onCreate().Now enable location ,open the app from recent app tray,check location is updated or not.

   @Override
protected void onResume() {
    super.onResume();
    if (isLocationServiceEnabled) {
        startLocationUpdates();
    }
}
๐ŸŒ
Android Central
forums.androidcentral.com โ€บ home โ€บ android developers โ€บ software development
FusedLocationProviderClient and Wakelocks | Android Central Forum
May 22, 2020 - I am implementing a solution to track location updates in my Application,both in foreground and background, and perform some task when location is updated. As per the Google recommendations in https://developers.google.com/andro...n.LocationRequest, android.app.PendingIntent), I used PendingIntent variant of requestLocationUpdates API.
๐ŸŒ
Hashnode
meetjainblogs.hashnode.dev โ€บ how-to-get-user-location-in-android
How to get User Location in Android
January 30, 2022 - In order to get the last location ...ProviderClient. It is actually a location service that combines GPS location and network location to achieve a balance between battery consumption and accuracy....
๐ŸŒ
GitHub
github.com โ€บ topics โ€บ fusedlocationproviderclient
fusedlocationproviderclient ยท GitHub Topics ยท GitHub
FusedLocationProviderClient is new way to fetch the user current location in terms of latitude and longitude. android java gradle google-maps location-services latitude longitude locationmanager fusedlocationapi runtime-permissions ...
๐ŸŒ
Meetmarigold
sdkdevelopers.meetmarigold.com โ€บ docs โ€บ android-location-updates
Android: Location Updates
Android location updates can be requested using the FusedLocationProviderClient class.
๐ŸŒ
B4X
b4x.com โ€บ home โ€บ forums โ€บ b4a - android โ€บ android questions
Mock Locations with New Fused_Location_Provider_GMS lib | B4X Programming Forum
March 20, 2024 - This is a new FusedLocationProviderGMS library that is based on the latest version of Google Mobile Services (GMS). Unlike the old version of the FusedLocationProvider library, this version uses the FusedLocationProviderClient class in place of the deprecated FusedLocationProvider class.