Home » Java » java – CountDownTimer stops at random by it self-Exceptionshub

java – CountDownTimer stops at random by it self-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:
countDownTimer = new CountDownTimer(time, 20) {
                @Override
                public void onTick(long l) {
                    textViewTimer.setText(formatTime(l));
                    time = l;
                    strTime = new StringBuilder();

                    strTime.append(df.format(gameView.percentage));
                    strTime.append("%");

                    textViewPercentage.setText(strTime.toString());

                    if(HoneyBeeGameView.isGameOver){
                        HoneyBeeGameView.isGameOver = false;
                        countDownTimer.onFinish();
                    }

                    if(gameView.percentage > 95){
                        time = 60*1000;
                        gameView.fillAllCells();
                        showNextLevelDialog();
                        hasTimerStarted = false;
                    }
                }

                @Override
                public void onFinish() {
                    showNextLevelDialog();

                }
            };
            countDownTimer.start();

CountDownTimer stops at random by it self, sometimes it works fine and other times it stops without
reaching any stopping condition

How to&Answers: