getLastKnownLocation now returns null but it was totally working a day ago ! now it's constantly in null, from different phones.
what could be the problem ? did I implement it in the wrong way ? The locationFetch thread runs constantly -with a while loop implemented inside- and is responsible for calling "onLocationChanged" function with each change.
Runnable locationFetchRun = new Runnable()
{
public void run()
{
tracker = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location;
boolean enabled;
// Initialize the location fields
while( !isFinishing() )
{
Log.i("Homepage","User id value "+user_id);
tracker = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
enabled = tracker
.isProviderEnabled(LocationManager.GPS_PROVIDER);
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
//Brick point
if(!enabled || activeNetworkInfo.isConnected()!= true)
{
continue;
}
provider = tracker.getBestProvider(criteria, true);
location = tracker.getLastKnownLocation(provider);
if (location != null)
{
gps_state = 1;
onLocationChanged(location);
}
else
gps_state = 0;
}
}
};
//Start location fetch thread
Thread locationFetch = new Thread(locationFetchRun);
locationFetch.start();
It didn't stop working actually, it was just taking a lot of time to fetch the coordinates.. I'll search for another solution to save time and phone battery ; starting from changing the whole function to setting a decent timeout at the end of the loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.