Code example for AtomicReference

Methods: get, sleep

0
    } 
 
    @Override 
    protected Location locateImpl() {
 
        final AtomicReference<Location> locationHolder = new AtomicReference<>();
 
        final LocationListener listener =
                new LocationUpdatesListener(locationHolder, providerName, Thread.currentThread());
 
        handler.post(new Runnable() {
            @Override 
            public void run() { 
                locationManager.requestLocationUpdates(providerName, 0, 0, listener);
            } 
        }); 
 
        try { 
            Log.d(TAG, "start sleeping");
 
            Thread.sleep(timeoutInSec * 1000);
 
            Log.d(TAG, "stop sleeping");
        } catch (InterruptedException e) {
            Log.d(TAG, "interrupted");
        } 
 
        handler.post(new Runnable() {
            @Override 
            public void run() { 
                locationManager.removeUpdates(listener);
            } 
        }); 
 
        return locationHolder.get();
    } 
 
    private static class LocationUpdatesListener implements LocationListener {
 
        private final String TAG;