Code example for Timer

Methods: scheduleAtFixedRate

0
 
        if(gps_enabled)
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
        if(network_enabled)
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
        timer1=new Timer();
        timer1.scheduleAtFixedRate(new GetLastLocation(), 5000,5000);
        return true; 
    } 
 
    LocationListener locationListenerGps = new LocationListener() {
        public void onLocationChanged(Location location) { 
            timer1.cancel(); 
            locationResult.gotLocation(location); 
            lm.removeUpdates(this); 
            lm.removeUpdates(locationListenerNetwork); 
        } 
        public void onProviderDisabled(String provider) {} 
        public void onProviderEnabled(String provider) {} 
        public void onStatusChanged(String provider, int status, Bundle extras) {} 
    };