检查CountDownTimer是否正在运行 [英] Checking if CountDownTimer is running

查看:117
本文介绍了检查CountDownTimer是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来查看CountDownTimer是否在运行,但我找不到办法,任何帮助将不胜感激

Ive been looking to see a method to see if a CountDownTimer is running or not, but I cant find a way to, any help would be greatly appreciated

if (position == 0) {

    mCountDown = new CountDownTimer((300 * 1000), 1000) {

        public void onTick(long millisUntilFinished) {
            mTextField.setText("seconds remaining: "
                    + millisUntilFinished / 1000);
        }

        public void onFinish() {
            mTextField.setText("0:00");
            String path = "/sdcard/Music/ZenPing.mp3";
            try {

                mp.reset();
                mp.setDataSource(path);
                mp.prepare();
                mp.start();

            } catch (IOException e) {
                Log.v(getString(R.string.app_name),
                        e.getMessage());
            }
        }
    }.start();

}

为此,我如何检查mCountDown是否正在运行?

For that how can I check if mCountDown is currently running?

推荐答案

只需放置 boolean 标志,该标志通过以下代码进行指示

Just put a boolean flag which indicate that by following code

boolean isRunning = false;

mCountDown = new CountDownTimer((300 * 1000), 1000) {

    public void onTick(long millisUntilFinished) {
        isRunning = true;
        //rest of code
    }

    public void onFinish() {
        isRunning= false;
        //rest of code
    }
}.start();

这篇关于检查CountDownTimer是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆