Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an infinite loop

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.

like image 833
Milky Way Avatar asked Nov 26 '11 11:11

Milky Way


People also ask

How can we create infinite loop?

We can create an infinite loop using while statement. If the condition of while loop is always True , we get an infinite loop.

What is an example of an infinite loop?

What is an Infinite Loop? An infinite loop occurs when a condition always evaluates to true. Usually, this is an error. For example, you might have a loop that decrements until it reaches 0.

What is an infinite loop How is it created?

An infinite loop is an instruction sequence that loops endlessly when a terminating condition has not been set, cannot occur, and/or causes the loop to restart before it ends. An infinite loop is also known as an endless loop.

Is it possible to create a loop that never ends?

An infinite loop is a sequence of instructions in a computer program which loops endlessly, either due to the loop having no terminating condition, having one that can never be met, or one that causes the loop to start over.


1 Answers

Hope this will help you.

public void countdown(){
    if (x != null) {
        x.cancel();
    }
    x = new CountDownTimer(20000, 1000) {
       public void onTick(long millisUntilFinished) {
        }
       public void onFinish() {
           showNotification();
            x.start();
        }
    };
 }
like image 74
freshDroid Avatar answered Oct 11 '22 20:10

freshDroid