applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
15 stars 6 forks source link

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

Closed Click2cloud-Eros closed 3 years ago

Click2cloud-Eros commented 3 years ago

Describe the query

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 method available for delay in Component class.

So, My question is

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

Stackoverflow link here:

**** https://stackoverflow.com/questions/69069553/what-is-the-equivalent-of-view-postdelayedrunnable-action-long-delaymillis-in

Additional information

Developer Platform: Windows DevEco Studio version: 2.1 Beta 4 SDK API version: 5

GowthamRayar commented 3 years ago

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);