I've read some questions about this, but I didn't quite find an answer that I needed. I want to understand how getLastLocation works internally. How last known location cached value is updated?
We have requirement where we need to get last known location of the device. Can anyone explain how getLastLocation works? I have seen that getLastLocation API returns null even if location-setting is ON. At the same time if I checked Google Map app and it is able to get the location (of-course it must be using requestLocationUpdates or any other API).
On my Nexus-5, I observed that getLastLocation returns null even after I launch Google Map app and then launch my app again. Even if location is detected correctly in Google Map app, getLastLocation API returns null.
How Android system updates the last known location? Does it update only when some app requests for location via requestLocationUpdates API? If Android system updates the last known location automatically then why do getLastLocation API returns null?
getLastLocation API Getting last known location
Points to be noted:
Location permission is granted.
Location Setting is ON
Same code works on few devices, but fails on few devices.
I am trying to get location from Google's FusedLocationProviderAPI and Android Framework LocationManager API.
I have checked all existing questions on Stackoverflow
It would be great if anyone can explain under what circumstances getLastLocation API can return null even if location setting is ON. Does anyone know how this works internally?