Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At some point I want my android background Service to execute something after 2 seconds. So - I had prepared a designated Handler:

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

and then I call

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

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?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900