示例:
final Runnable updateTitleRunnable = new Runnable() {
public void run() {
// udpate UI controls
updateActionbarText();
}
};
public Handler updateTitleHandler = new Handler() ;
private void updateOnlineStatus() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
String url = getString(R.string.baseurl2)+"Ping.ashx";
String rst = UtilHttp.doHttpGet(m_context, url);
if(rst == null){
m_onlineStatus = OFFLINE;
}else {
m_onlineStatus = "ok".equals(rst) ? ONLINE : OFFLINE;
}
updateTitleHandler.post(updateTitleRunnable);
}
},0,10000);
}