Android: How to make function wait for another?
I want to send an sms message containing current location of user. How do I make the sending function w开发者_C百科ait till the location is calculated?
Read about intents and you will find out. The trick is you issue an intent when you get the location.
private class DeafLocationListener implements LocationListener {
private final String provider;
public DeafLocationListener(String provider) { this.provider = provider; }
@Override public void onLocationChanged(Location location) {
Log.d(TAG, String.format("onLocationChanged triggered (%s)", provider));
// SEND SMS HERE
}
@Override public void onProviderDisabled(String provider) { /*nop*/ }
@Override public void onProviderEnabled(String provider) { /*nop*/ }
@Override public void onStatusChanged(String provider, int status, Bundle extras) { /*nop*/ }
}
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeGPS, minDistanceGPS, new DeafLocationListener("GPS"););
精彩评论