如果我有像example.com/time.php这样的东西,输出只有20000那么我如何将其链接到控制刷新时间,Any Idea?
Thread t = new Thread() {
@Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(10000); // here is the number which should be linked to the webpage output
runOnUiThread(new Runnable() {
@Override
public void run() {
// update View here!
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
答案 0 :(得分:0)
您应该使用handler来更容易实现。
Handler handler = new Handler();
Runnable test = new Runnable() {
@Override
public void run() {
//do work
handler.post(test, 4000); //wait 4 sec and run again, you can change it programmatically
}
};
public void stopTest() {
handler.removeCallbacks(test);
}
public void startTest() {
handler.post(test,0); //wait 0 ms and run
}