Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of view.postDelayed(Runnable action, long delayMillis) in harmonyos?

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 ?

like image 780
Shivam Jamaiwar Avatar asked Sep 06 '21 05:09

Shivam Jamaiwar


3 Answers

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);
like image 65
shirley Avatar answered Oct 20 '22 05:10

shirley


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);
like image 27
Gowtham GS Avatar answered Oct 20 '22 04:10

Gowtham GS


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);
like image 23
zhangxaochen Avatar answered Oct 20 '22 06:10

zhangxaochen