applibgroup / HarmonyOS-Knowledgebase

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

What is the alternative in HarmonyOS for postDelayed() in android? #29

Closed chiragbhatt3 closed 3 years ago

chiragbhatt3 commented 3 years ago

Query description

I am working on an HarmonyOS library that prompts users to review the app on the app gallery. I want to display a prompt thanking the user after he/she reviews the app and the prompt should fade after "int thanksDisplayTimeMs". In Android, it is implemented using

postDelayed(new Runnable(){
     @Override
     public void run() {
     }
 }, thanksDisplayTimeMs);

What is the alternative for harmonyos for the same?

Stackoverflow link:

https://stackoverflow.com/questions/68573632/what-is-the-alternative-in-harmonyos-for-postdelayed-in-android

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.303 SDK API version: 5 SDK version: 2.1.1.21 Device: Not required Device OS version: Not required

Regards, Chirag

Meknaj commented 3 years ago

This can be achieved using EventHandler and posting the task on the main thread as shown below new EventHandler(EventRunner.getMainEventRunner()).postTask(Runnable runnable, Object o)) For achieving the fading effect on view, view.createAnimatorProperty() and the required duration can be mentioned using setDuration passing the time in ms