I have plans to create an interval app using timers. It should just be the most basic So I’ll have to add some more when I’ve understood the basics. What I want to achieve is to select the number of minutes an interval should last, yet how many times this interval should go. Like a interval that last 1 minute and goes 8 times.
The question is which timer is best to use? I have tried me on the Android Countdown Timer and it seems to work. But is there another one which is better?
I have plans to create an interval app using timers. It should just be
Share
I would always recommend using a
Handler.It’s a little more work than the built in classes, but I find that it is vastly more efficient and you have more control over it.
The Handler is a class that will handle code execution over a specific
Looper/Threadby default, the Thread it is created in, Otherwise you can specify where the Handler executes its code by passing in theLooperto theHandlerconstructor like –new Handler(Looper.getMainLooper());The reason I would recommend the looper is because you have a higher flexibility of control, as it is a slightly lower down abstraction over the
TimerTaskmethods.Generally they are very useful for executing code across threads. E.g. useful for piping data across threads.
The two main uses are:
Simple use!
Or you can use messages, which reduce object creation. If you are thinking about high speed updating UI etc – this will reduce pressure on the garbage collector.
Obviously this is not a full implementation but it should give you a head start.