TimerTask, Geolocation and Looper

399 Views Asked by At

I need to perform the follow logic in my application: Every minute, I want to be able to listen to GPS location for 20 seconds to get a GEO-location fix.

This obviously needs to run a different thread than the UI thread.

I am however having some problems with using looper and timertask in conjuction...

What's the best way to achieve this?

1

There are 1 best solutions below

0
On BEST ANSWER

I guess you need to use a Service :

Android doc :

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.

So the Service start the LocationManager using requestLocationUpdates() and implements LocationListener.

Then you have (at least) two solutions (depending on what you want to do) :

  • dispatch the event to the Activity that need to use the Location ( with a Broadcast for example )
  • the Activity has an access to the service and uses a getter to get the latest location.