Reputation: 666
Im trying to get my GPS working in a service but its not working. The GPS bit works on its own but not in the service.
I have tried debugging with System.out.println() and fond where it stops working but cant work out why it all looks good.
public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("test 1");
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
System.out.println("test 2");
LocationListener lli = new myLocationListener();
System.out.println("test 3");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, lli);
System.out.println("test 4");
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
}
class myLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if(location != null){
pet.setMeter();
}
}
It gets to Test 4 then dies. I am lost at why so if anyone can help that would be awesome thanks.
Upvotes: 0
Views: 282
Reputation: 7108
A nice gps tracker guide: http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
Just needed to add this.mLocation = location in onLocationChanged
He also wraps it into a service.
Upvotes: 1