开发者

calling a function in android after intervals?

开发者 https://www.devze.com 2023-01-06 15:43 出处:网络
I would like to call a function ABC() every 10 seconds, a开发者_高级运维gain and again till I use return statement to quit. But I don\'t want to use any Java Time function.

I would like to call a function ABC() every 10 seconds, a开发者_高级运维gain and again till I use return statement to quit. But I don't want to use any Java Time function.

Anyone can guide me how to achieve this?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号