在postDelayed的延迟之后,Runnable很长时间了 [英] Runnable is excecuted long time after postDelayed's delay

查看:612
本文介绍了在postDelayed的延迟之后,Runnable很长时间了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些时候,我希望我的Android背景服务在2秒后执行某些操作。所以 - 我准备了一个指定的处理程序:



At some point I want my android background Service to execute something after 2 seconds. So - I had prepared a designated Handler:

private Handler handler;
...
HandlerThread thread = new HandlerThread("LNT");
thread.start();
handler = new Handler(thread.getLooper());



然后我调用< br $> b $ b


and then I call

handler.postDelayed (new Runnable(){
    public void run(){
        doSomething();
}, (long)(2000));



有时候soSomething()在2秒后被调用,但很多时候需要15秒!!



我做错了什么?

在特定时间段之后还有另一种方法可以运行吗?


sometimes soSomething() is being called after 2 seconds, but many times it take up to 15 seconds !!

What am I doing wrong?
Is there another way to run something after a specific period of time?

推荐答案

这篇关于在postDelayed的延迟之后,Runnable很长时间了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆