Question

I have this perodic Handler:

int interval = 35000;

Runnable runnableForConsumption = new Runnable() {
        @Override
        public void run() {

            handler.postDelayed(runnableForConsumption, interval);
            new ConnectWSTask().execute();
        }
    };

    void startRepeatingTask() {
        runnableForConsumption.run();

        }

    void stopRepeatingTask() {
        handler.removeCallbacks(runnableForConsumption);
    }

And I want for the first run an interval of 2000ms and after this run I want an interval of 35000ms.

Is it possible to change the interval of this handler during running?

Or is there any other possibility to do something like that?

Was it helpful?

Solution

you can try this:

    public void run(){

        handler.postDelayed(runnableForConsumption, interval);

        if(interval == 2000){
            interval = 3500;
        }
        new ConnectWSTask().execute();
    }

The point is you change interval to 3500 before your second postDelayed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top