How to make an Android program 'wait'

后端 未结 8 1322
深忆病人
深忆病人 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:43

    Do something like the following. Here is a link to the reference, this might be helpful.

    final MyActivity myActivity = this;   
    
        thread=  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        wait(3000);
                    }
                }
                catch(InterruptedException ex){                    
                }
    
                // TODO              
            }
        };
    
        thread.start();   
    

提交回复
热议问题