Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  176] [ 7]  / answers: 1 / hits: 130031  / 14 Years ago, thu, january 27, 2011, 12:00:00

Can anyone tell me if an equivalent for setInterval/setTimeout exists for Android? Does anybody have any example about how to do it?


More From » java

 Answers
52

As always with Android there's lots of ways to do this, but assuming you simply want to run a piece of code a little bit later on the same thread, I use this:


new android.os.Handler(Looper.getMainLooper()).postDelayed(
new Runnable() {
public void run() {
Log.i("tag", "This'll run 300 milliseconds later");
}
},
300);

.. this is pretty much equivalent to


setTimeout( 
function() {
console.log("This will run 300 milliseconds later");
},
300);

[#94026] Tuesday, January 25, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
timothyc

Total Points: 233
Total Questions: 103
Total Answers: 103

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
timothyc questions
Sun, Jun 12, 22, 00:00, 2 Years ago
Sun, May 22, 22, 00:00, 2 Years ago
Fri, Jun 12, 20, 00:00, 4 Years ago
;