Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add delay between two actions

I wanted te delay the interstitial with 1 second after clicking on a button. I used Thread.sleep() but it didnt work coz the message that it must be shown after clicking the button is also delayef. I want to click on the button and wait the message 1 secobd then show the ad.

like image 339
err ais Avatar asked Nov 27 '25 06:11

err ais


2 Answers

Maybe this is what you are looking for:

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

That will delay the operations in run() for the specified ms in milliseconds.

like image 178
mrtn Avatar answered Nov 29 '25 20:11

mrtn


You can use Handler with postDelay. pass duration in milliseconds then run() will call after given duration.

             Handler h = new Handler();
                Runnable r = new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        // code that will run after 1 second(1000 ms)
                    }
                };
                h.postDelayed(r, 1000);
like image 21
NehaK Avatar answered Nov 29 '25 20:11

NehaK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!