err ais
err ais

Reputation: 31

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.

Upvotes: 3

Views: 553

Answers (2)

mrtn
mrtn

Reputation: 889

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.

Upvotes: 3

NehaK
NehaK

Reputation: 2737

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

Upvotes: 1

Related Questions