Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Check if Runnable is running

I want to check if either the Runnable is alive or not in my service. Is there a way i could do this?

private Runnable sendData = new Runnable() {
    public void run() {
        try {
            superToast.show();
            screenOn();
            vibrate();
            mHandler.postDelayed(sendData, time);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
};
like image 423
beLejer Avatar asked May 06 '14 06:05

beLejer


1 Answers

you can create a boolean variable and check its value whether it is running or not

boolean isRunning = false;

private Runnable sendData = new Runnable() {
    public void run() {
        try {
            isRunning = true;
            superToast.show();
            screenOn();
            vibrate();
            mHandler.postDelayed(sendData, time);
        } catch (Exception e) {
            e.printStackTrace();
            isRunning = false;
        }
    }
};

and now check for isRunning, if its true it is running else not running

like image 96
Waqar Ahmed Avatar answered Oct 01 '22 12:10

Waqar Ahmed