Is there something that looks like the javax.swing.Timer
on Android. I know how to create own Threads, but is there something that is like the swing-timer?
相关问题
- 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
The main point of
javax.swing.Timer
is that it executes tasks on GUI thread (EDT - event dispatching thread). This makes it safe to manipulate Swing components.In Android there is also EDT and you should only manipulate GUI elements on EDT. To delay your code and then run it on EDT use
view.postDelayed(runnable)
.There is also Java's TimerTask. Here's an example from my code where I'm playing audio samples:
You are probably looking for the class
android.os.CountDownTimer
You can inherit the class like this: