我正在编写一个处理程序以运行固定量(30 秒)的时间。基于它更新计数器以绘制视图组件。
counterRunnable = new Runnable() {
int currV = 0;
public void run(){
if(count >= 360) {
counterHandler.removeCallbacks(this);
onTimerComplete();
} else {
count++;
counterHandler.postDelayed(this, 83); // (30/360) = ~83
}
}
};
因为我正在运行它以延迟83ms 360 时间(83*360 = 29880ms ~30 秒),但它运行了~39 秒。如果我做错了任何建议。
分析: 我用Timer进行了同样的检查(以固定速率计划),它的性能比Handler.postDelay更好,但仍然有任何建议为什么 postDelay 在这里最差?