Code example for Timer

Methods: purgeschedule

0
 
    private void startPullingMessages() { 
        int pullTime = prefs.getPullTimeInSeconds() * 1000;
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, pullTime / 3, 5, locationBean);
        task = new UpdaterTask();
        timer.schedule(task, 300, pullTime);
    } 
 
    @Override 
    public void onDestroy() { 
        super.onDestroy(); 
        Log.d(TAG, "UpdaterService destroyed");
        stopPullingMessages(); 
    } 
 
    private void stopPullingMessages() { 
        locationManager.removeUpdates(locationBean);
        task.cancel();
        timer.purge();
    } 
 
    @Override 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
        stopPullingMessages();