When I open the app it reports the coordinates of the device. Then I change the coordinates using the emulator's menu, close and reopen the app, and the old coordinates still show. After opening Google Maps, for a while the location icon is grey and then it jumps to the new location. Then I open my app again and it's in the correct place now.
The code I'm using is really simple. Here it is:
FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
fusedLocationClient.getLastLocation().addOnCompleteListener(
new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
Location location = task.getResult();
Toast.makeText(MainActivity.this, "" + location.getLongitude(), Toast.LENGTH_LONG).show();
}
}
);
I assume Google Maps is somehow force refreshing the location. How can I do this on my own app?