Android上的计时器是否具有容差?
创始人
2024-10-10 04:32:56
0

Android上的计时器有一定程度的容差。例如使用Handler的postDelayed()方法:

Handler handler = new Handler();
Runnable runnable = new Runnable() {
    @Override
    public void run() {
        // TODO: do something
        handler.postDelayed(this, delayMillis);
    }
};
handler.postDelayed(runnable, delayMillis);

上述代码中,run()方法中的代码执行时间并不会精确等于delayMillis,可能会有一定的时间差。因此,如果需要在精确时间点执行代码,可以将容差值减去执行代码的耗时:

long startTime = System.currentTimeMillis();
// do something that takes time
long endTime = System.currentTimeMillis();
long timeDiff = endTime - startTime;

handler.postDelayed(this, delayMillis - timeDiff);

相关内容

热门资讯

突发!hhpoker透视脚本下... 突发!hhpoker透视脚本下载,微信微乐辅助器使用教程,分享透视(确实有挂)-哔哩哔哩1)hhpo...
透视总结!aapoker脚本,... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
突发!wepoker辅助器最新... 突发!wepoker辅助器最新版本更新内容,微信微乐自建房辅助工具,揭幕透视(详细教程)-哔哩哔哩1...
透视总结!hhpoker视频巡... 透视总结!hhpoker视频巡查真的假的,hh poker辅助器先试用(透视)确实有神器(哔哩哔哩)...
今年以来!epoker免费透视... 今年以来!epoker免费透视脚本,微乐小程序脚本入口,开挂脚本(揭秘有挂)-哔哩哔哩1、epoke...
透视解迷!hhpoker辅助器... 透视解迷!hhpoker辅助器,hhpoker透视脚本(透视)确实存在有神器(哔哩哔哩)1、让任何用...
为了进一步!pokerrrr2... 您好,pokerrrr2辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
脚本辅助!aapoker免费透... 脚本辅助!aapoker免费透视脚本,aapoker怎么设置抽水(透视)都是真的是有方法(哔哩哔哩)...
此事迅速冲上热搜!hh pok... 此事迅速冲上热搜!hh poker软件,微信微乐辅助器免费安装,解谜透视(新版有挂)-哔哩哔哩1、h...
脚本专业!德普之星透视辅助软件... 脚本专业!德普之星透视辅助软件,德普之星的辅助工具介绍(透视)总是有方法(哔哩哔哩)1、实时透视辅助...