我有一个实现 LocationListener 的类
public class GetLocation implements LocationListener {
@Override
public void onLocationChanged(Location location) {
Log.i("GetLocation", "Location changed: " + location.getLatitude()
+ ", " + location.getLongitude());
}
在我的活动中,
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final GetLocation locationListener = new GetLocation();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locationListener);
..... //Check whether the location is changed
locationManager.removeUpdates(locationListener);
updateGPStoServer();
在 onLocationChanged() 被调用一次后,我想做一个上传任务并取消监听器,所以我问我如何等待 onLocationChanged() 然后做我的任务?