[Solved] Android call api route every few seconds


Try this

declare Timer global

Timer timer;

add this code inside onCreate() method

timer = new Timer();
timer.scheduleAtFixedRate(new RemindTask(), 0, 3000); // delay in seconds

create a new class like this

private class RemindTask extends TimerTask {


        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                public void run() {

                    // call your method here

                   getImageFromApi();
                }
            });

        }
    }

3

solved Android call api route every few seconds