After onLocationChanged() is called once, I want to do a upload task and cancel the listener, so I am asking how can I wait for the onLocationChanged() then do my tasks?
I think you need to move the call to updateGPStoServer()
into your Listener.onLocationChanged
method; that would implement the "waiting" that you're looking for. (On a separate note: updateGPStoServer()
should be implemented to create a background Thread to do the updates to the server. But you knew that, right? :-)
Also, it sounds like you really want to be calling LocationManager.requestSingleUpdate
instead of LocationManager.requestLocationUpdates
. That would remove the need to call locationManager.removeUpdates(locationListener)
.