简体   繁体   English

如果出现活动对话框,如何暂停倒数计时器

[英]How to pause the countdown timer if activity dialog appeared

How can I pause the countdownTimer if a dialog need to appear first.如果需要首先出现对话框,我该如何暂停倒计时计时器。 What can I do so that the timer will not start until I click the ok button.我该怎么做才能让计时器在我单击确定按钮之前不会启动。

 countDownTimer = new CountDownTimer(320000, 1200) {
        @Override
        public void onTick(long l) {
            timeText.setText(String.valueOf(timeValue));

            timeValue = timeValue - 1;
            if (timeValue == -1){
                FLAG = 3;
                playAudio.setAudioforEvent(FLAG);
                timerDialog.timerDialog();
                countDownTimer.cancel();
                dbHandler.addScore2(tag,Integer.parseInt(txtCorrect.getText().toString()));

            }

        }
        @Override
        public void onFinish() {

            // timerDialog.timerDialog();

        }

    }.start();

This is the dialog that will appear first.这是首先出现的对话框。

 public void fillDialog(){


    fillDialog = new Dialog(mnContext);
    fillDialog.setContentView(R.layout.activity_instruction_fill);

    final Button btdialog = (Button) fillDialog.findViewById(R.id.ok_btn_fill);

    btdialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            fillDialog.dismiss();

        }
    });

You can use the countdownTimer.cancel() method to pause the countdown timer.您可以使用 countdownTimer.cancel() 方法暂停倒数计时器。 When the dialog appears, call this method to pause the timer.当对话框出现时,调用此方法暂停计时器。 When the user clicks the "OK" button on the dialog, you can then call the countdownTimer.start() method to resume the timer from where it left off.当用户单击对话框上的“确定”按钮时,您可以调用 countdownTimer.start() 方法从停止的地方恢复计时器。 Alternatively, you can also use countdownTimer.pause() and countdownTimer.resume() to pause and resume the timer.或者,您也可以使用 countdownTimer.pause() 和 countdownTimer.resume() 来暂停和恢复计时器。 It would be good to keep in mind that countdownTimer is a android class and you need to call the above methods from your activity class最好记住 countdownTimer 是一个 android class 并且您需要从您的活动 class 中调用上述方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM