Introduction

I’m spent countless hours trying to find the best way to provide geolocation across a whole Android application and I found that my approach was often too short-minded to avoid service leak on my application lifecycle. So I though about rebuilding my implementation and here is the result.

I find it quite convenient to use and yet doing the job ! Hopefully it comes without (too many) memory leaks.You might want to optimize providers call to avoid them to be on constantly so that you can save battery. However since that’s not the purpose, I kept the project simple.

 

MyCUBMapView

The sample project

https://github.com/Kayrnt/SimpleLocationService

How to use

  • You should have an application with overrides the onTerminate() like in the sample.
  • Your activities using geolocation should use extends GeolocatedActivity like in the sample or just override the OnResume and OnPause methods
  • Then just use LocationServiceHelper.getInstance(getApplicationContext).getLocation() to retrieve latest location if existing !
  • Finally you might want to use a listener on some object then just use implements ILocationListener and put LocationServiceHelper.getInstance(getApplicationContext).addListener(listener) and remove method as in the sample.
Publicités