I am creating a custom component in HarmonyOS using Java SDK, Where I have to perform some task after some delay with Component instance.
In Android, we have postDelayed(Runnable action, long delayMillis)
method in View class. So we can achieve above requirement as follow
view.postDelayed(runnable, 100);
but, In HMOS java SDK, I seen there is no any api available for delay in Component class.
So, My question is
What is the equivalent of view.postDelayed(Runnable action, long delayMillis) in harmonyos ?
You could also refer to the following code:
getUITaskDispatcher().delayDispatch(new Runnable() {
@Override
public void run() {
// Here's the task you want to delay.
}
}, 100);
currently HarmonyOS doesn't provide exact alternative for View.postDelayed(..) , Instead you can achieve similar UI post functionality using ohos.eventhandler.EventHandler API, Sample Usage is as follows
EventHanlder eventhandler = new EventHandlder(EventRunner.getMainEventRunner());
eventhandler.postTask(runnable, timeInMillis);
You could also refer to the following code:
getUITaskDispatcher().delayDispatch(new Runnable() {
@Override
public void run() {
// Here's the task you want to delay.
}
}, 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With