androidgeolocationandroid-asynctasklocationlistener

The locationListener is only invoked once


I want to send some data along with coordinates to a remote server each 10 seconds. I thought, that the best match would be the

public void onCreate( Bundle savedInstanceState ) {
  //snip
  locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 10000, 0, new SendingLocationListener() );
}

in the listener I have the following code:

public void onLocationChanged( Location location ) {
  if( null == location ) return;
  TrackerNotifierTask task = new TrackerNotifierTask();
  task.execute( location );
}

the TrackerNotifierTask uses the httpclient in it's doInBackground() method, so it's pretty simple.

Now, if I start the activity, I can see that the onLocationChanged() gets executed and the data hits the remote server successfully. But only once! No matter what I do later, changing coords or anything, the task does not get called.

Is this the right way of implementing such thing in android or shall I resort to some background-service?


Solution

  • Please see this.

    It works as expected when LocationListener is implemented as an anonymous class.