Rohith Nandakumar
Rohith Nandakumar

Reputation: 11427

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 wait till the location is calculated?

Upvotes: 1

Views: 1271

Answers (2)

Schildmeijer
Schildmeijer

Reputation: 20946

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"););

Upvotes: 0

Pentium10
Pentium10

Reputation: 207912

Read about intents and you will find out. The trick is you issue an intent when you get the location.

Upvotes: 1

Related Questions