How to “wait” a Thread in Android

前端 未结 5 1826
夕颜
夕颜 2020-12-30 18:18
private void startGameTimeElapseThread(){
    new Thread(new Runnable() {
        Date d = new Date();
        public void run() {
            while (gameOn){
               


        
5条回答
  •  不思量自难忘°
    2020-12-30 19:01

    I just add this line exactly as it appears below (if you need a second delay):

    try {
        Thread.sleep(1000);
    } catch(InterruptedException e) {
        // Process exception
    }
    

    I find the catch IS necessary (Your app can crash due to Android OS as much as your own code).

提交回复
热议问题