Getting Repeated Current Location Inside A Service In Android?
I am calling a service were i will get current location at some interval and match the location with a location passed to the service.and if it is in a close range it will buzz the
Solution 1:
Your code
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
is put in the run() method of an anonymous Runnable class, that means the this
keyword is referring to that anonymous Runnable class instead of your Service class. Therefore simply changing the code to this will resolve the issue:
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addApi(LocationServices.API)
.addConnectionCallbacks(LocBuzzService.this)
.addOnConnectionFailedListener(LocBuzzService.this)
.build();
Additionally, this code doesn't take very much time to execute, so you can just move it out of the anonymous Runnable and it'll work as well.
Post a Comment for "Getting Repeated Current Location Inside A Service In Android?"