Java – How to add a delay between two Actions

How to add a delay between two Actions… here is a solution to the problem.

How to add a delay between two Actions

I want to delay the interstitial by 1 second after clicking the button.
I used Thread.sleep() but it didn’t work because the message that had to be displayed after clicking the button was also delayef.
I want to click the button and wait for the message for 1 second, then the ad is displayed.

Solution

Maybe that’s what you’re looking for:

new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
        showMessage();
        ...
      }
    }, ms);

This delays the operation in run() by the specified ms in milliseconds.

Related Problems and Solutions