See Start a Location Strategy
I did some research: I turned on the GPS and waited for a fix. Then I turned off the GPS and drove 50 km (31 miles). Then I used the code from A Deep Dive Into Location to get all getLastKnownLocation. I tried this twice, first with GPS turned off and second with GPS turned on, but without a fix:
1) when GPS is disabled, I got - Provider: network, correct location with an accuracy of 680 m - Provider: passive (mProvider = network), same place as above, at the same time as above - Provider: gps location null
So, I found out that when gps is disabled, you are not getting getLastKnownLocation from the GPS location provider.
2) with GPS on - Provider: network, correct location with an accuracy of 652 m - Provider: passive (mProvider = network), the same place as above, at the same time as above - Provider: gps, location, as was 2 hours earlier with an accuracy of 12 m, time was 2 hours earlier
Here I learned that old messages are not invalid, itβs even obvious that they are wrong.
So, to summarize: when the provider is active, it stores the last received location returned via getLastKnownLocation. If the provider is disabled, you do not even get getLastKnownLocation. Please note that I tested this with a GPS provider, other providers may react differently.
Chrlipp
source share