Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if CountDownTimer is running

Tags:

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?

like image 902
user3224105 Avatar asked Jan 30 '14 08:01

user3224105


People also ask

How do you check count down timer is running?

use the isTimerRunning property to track the status. Show activity on this post. Check if the CountDownTimer is Running and also if the app is running in the background.


1 Answers

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();
like image 74
Chintan Rathod Avatar answered Oct 10 '22 06:10

Chintan Rathod