在我的应用程序中,我会在一段时间间隔内继续更新一些信息。所以我这样做了
handler = new Handler();
and then some Task
handler.postDelayed(runLocation, 1000);
public Runnable runLocation = new Runnable(){
@Override
public void run() {
MainActivity.this.handler.postDelayed(MainActivity.this.runLocation, 100);
};
我的问题是我想在某个时间点阻止这种运行。如何做到这一点? 你能帮助我吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
@Override
public void run() {
if(isStopHandler){
MainActivity.this.handler.removeCallbacks(this);
return;
}
// do your runnable work
// set isStopHandler = true when needed so next time this method is executed, it will get inside if cond.
};