Android Lightweight Timer

Introducing: LightweightTimer. LightweightTimer allows to schedule tasks for repeated future execution. It pretty much serves the same purpose of Java’s Timer class, but does not require extra thread creation. Instead, LightweightTimer uses Android’s Handler class to schedule its tasks. This is important when creating Android apps because memory is at a premium, and creating a thread for every little repeating task you have seems wasteful. Also, the LightweightTimer has the added benifit of executing on the main thread, which is often what you want.

It’s super easy to use:

LightweightTimer timer = new LightweightTimer(new Runnable(){  
 public void run() { 
    Log.i("", "This is my task that will run on the Main thread every 3 seconds until I call stop()"); 
}, 3000);

Paul Soucy

Read more posts by this author.