How to make an Android program 'wait'

后端 未结 8 1306
深忆病人
深忆病人 2020-12-16 02:15

I want to cause my program to pause for a certain number of milliseconds, how exactly would I do this?

I have found different ways such as Thread.sleep( time )

8条回答
  •  不思量自难忘°
    2020-12-16 02:55

    You can use the Handler class and the postDelayed() method to do that:

    Handler h =new Handler() ;
    h.postDelayed(new Runnable() {
        public void run() {
                     //put your code here
                  }
    
                }, 2000);
    }
    

    2000 ms is the delayed time before execute the code inside the function

提交回复
热议问题