Alex Rivera | Logout

What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

Asked 2011-01-27T14:58:02.893
176

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

Edit
Report

1 Answer

13

Depending on what you actually want to achieve, you should take a look at Android Handlers:

http://developer.android.com/reference/android/os/Handler.html

If you previously used javascript setTimeout() etc to schedule a task to run in the future, this is the Android way of doing it (postDelayed / sendMessageDelayed).

Note that neither Handlers or Timers makes an Android phone wake up from sleep mode. In other words, if you want to schedule something to actually happen even though the screen is off / cpu is sleeping, you need to check out the AlarmManager too.

answered 2011-01-27T16:48:47.870

Your Answer