Calling a function in android after intervals?

I would like to call a function ABC()every 10 seconds, again and again, until I use the return statement to exit. But I do not want to use any Java function Time.

Can anyone advise me how to do this?

+3
source share
1 answer

Use CountDownTimer

 CountDownTimer t = new CountDownTimer( Long.MAX_VALUE , 10000) {

        // This is called every interval. (Every 10 seconds in this example)
        public void onTick(long millisUntilFinished) {
            Log.d("test","Timer tick");
        }

        public void onFinish() {
            Log.d("test","Timer last tick");            
            start();
        }
     }.start();
+7
source

Source: https://habr.com/ru/post/1754205/


All Articles