Android-检查Runnable是否正在运行 [英] Android - Check if Runnable is running
本文介绍了Android-检查Runnable是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查Runnable是否仍在我的服务中.我有办法吗?
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();
}
}
};
推荐答案
您可以创建一个布尔变量并检查其值是否在运行
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;
}
}
};
现在检查isRunning,如果为true,则表示正在运行,否则未运行
and now check for isRunning, if its true it is running else not running
这篇关于Android-检查Runnable是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文