Checking if CountDownTimer is running

user3224105 picture user3224105 · Jan 30, 2014 · Viewed 17.3k times · Source

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();

}

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

Answer

Chintan Rathod picture Chintan Rathod · Jan 30, 2014

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();