How to create an infinite loop

2019-04-30 00:31发布

Ok,I need to create an infinite loop on a countdown. My code is:

public void countdown() {
    if (x != null) {
        x.cancel();
    }

    x = new CountDownTimer(20000, 1000) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            showNotification();
        }
    };
    x.start();
}

x is just a static countdowntimer variable. The problem is that I tried many methods to make the above code work,I mean when the countdown ends,and it displays that notification,it should start again and so on....but I can't find a way to do it.

7条回答
啃猪蹄的小仙女
2楼-- · 2019-04-30 01:29

You can just use a while loop:
while (true) {
// do stuff
}

When it has done "the stuff" it wil start again, infinite!

查看更多
登录 后发表回答