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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
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
/Thread
by default, the Thread it is created in, Otherwise you can specify where the Handler executes its code by passing in theLooper
to theHandler
constructor 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
TimerTask
methods.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.