Android Repeat Task Execution at Interval/Delay Until (Java)

April 14, 2019
final Timer timer = new Timer();

timer.schedule(new TimerTask() {
    @Override
    public void run() {
        // do something in background thread
        int status = ...

        if (status == 1) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // do something in main/ui thread
                }
            });

            timer.cancel();
        }
    }
}, 1000);
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.