My app is designed to track user's location periodically and send it to server, Recently I changed my code with Google play services Location API.
I created the locationclient and connected to the service in onStartCommand
public int onStartCommand(Intent intent, int flags, int startId) { setUpLocationClientIfNeeded(); if(!mLocationClient.isConnected() || !mLocationClient.isConnecting()) mLocationClient.connect(); return START_STICKY; }
and in onConnected method, I send a location request,
@Override public void onConnected(Bundle arg0) { System.out.println("Connected ..."); mLocationClient.requestLocationUpdates(REQUEST, this); }
The REQUEST object is,
private static final LocationRequest REQUEST = LocationRequest.create() .setInterval(5*60*1000) // 5 minutes .setFastestInterval(3*60*1000) // 3 minutes .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Now the issue is,
What is the issue with my above code?. ( I couldnt see any log for 'disconnected' also)
Full source code for a background service available here:
https://gist.github.com/blackcj/20efe2ac885c7297a676
Try adding the super call to your onStartCommand.
/** * Keeps the service running even after the app is closed. * */ public int onStartCommand (Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); setUpLocationClientIfNeeded(); if(!mLocationClient.isConnected() || !mLocationClient.isConnecting()) { mLocationClient.connect(); } return START_STICKY; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With