如何与QUOT;等待"在Android的线程 [英] How to "wait" a Thread in Android

查看:98
本文介绍了如何与QUOT;等待"在Android的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私人无效startGameTimeElapseThread(){
    新主题(新的Runnable(){
        日期D =新的日期();
        公共无效的run(){
            而(gameOn){
                Log.d(TAG,+ d.getTime()++ gameStatus.getLastTimeUpdated());

                postInvalidate(795,150,1024,300);
                尝试 {
                    同步(本){
                        等(1000);
                    }
                }赶上(InterruptedException异常E){
                    // TODO自动生成的catch块
                    Log.d(TAG,等待没有工作!);
                    e.printStackTrace();
                }
            }
        }
    })。开始();
}
 

在这里,我想使所谓的Log.d和postInvalidate每隔一秒。但是,当我从LogCat中检查它似乎循环运行速度比我希望它是。为什么犯规这个循环只是等待1000毫秒?

以下是在LogCat中的输出。所以你可以看到它不是睡了1秒都没有。我用视频下载以及(你暗示后)

  11月5日至27日:40:10.060:DEBUG / NOPSA-P(4546):1306496408950 1306496387535
十一月五号日至27日:40:10.070:DEBUG / NOPSA-P(4546):1306496410037 1306496387535
十一月五号日至27日:40:10.232:DEBUG / NOPSA-P(4546):1306496410201 1306496387535
十一月五号日至27日:40:10.250:DEBUG / NOPSA-P(4546):1306496408214 1306496387535
十一月五号日至27日:40:10.310:DEBUG / NOPSA-P(4546):1306496405988 1306496387535
十一月五号日至27日:40:10.361:DEBUG / NOPSA-P(4546):1306496409327 1306496387535
十一月五号日至27日:40:10.431:DEBUG / NOPSA-P(4546):1306496410398 1306496387535
十一月五号日至27日:40:10.521:DEBUG / NOPSA-P(4546):1306496409478 1306496387535
十一月五号日至27日:40:10.593:DEBUG / NOPSA-P(4546):1306496410566 1306496387535
十一月五号日至27日:40:11.230:DEBUG / NOPSA-P(4546):1306496409678 1306496387535
十一月五号日至27日:40:11.230:DEBUG / NOPSA-P(4546):1306496410201 1306496387535
十一月五号日至27日:40:11.241:DEBUG / NOPSA-P(4546):1306496409878 1306496387535
十一月五号日至27日:40:11.241:DEBUG / NOPSA-P(4546):1306496410037 1306496387535
十一月五号日至27日:40:11.241:DEBUG / NOPSA-P(4546):1306496408950 1306496387535
十一月五号日至27日:40:11.260:DEBUG / NOPSA-P(4546):1306496408214 1306496387535
十一月五号日至27日:40:11.314:DEBUG / NOPSA-P(4546):1306496405988 1306496387535
十一月五号日至27日:40:11.314:DEBUG / NOPSA-P(4546):1306496411254 1306496387535
十一月五号日至27日:40:11.361:DEBUG / NOPSA-P(4546):1306496409327 1306496387535
十一月五号日至27日:40:11.431:DEBUG / NOPSA-P(4546):1306496410398 1306496387535
十一月五号日至27日:40:11.520:DEBUG / NOPSA-P(4546):1306496409478 1306496387535
十一月五号日至27日:40:11.551:DEBUG / NOPSA-P(4546):1306496411508 1306496387535
十一月五号日至27日:40:11.712:DEBUG / NOPSA-P(4546):1306496410566 1306496387535
十一月五号日至27日:40:11.881:DEBUG / NOPSA-P(4546):1306496411865 1306496387535
十一月五号日至27日:40:12.051:DEBUG / NOPSA-P(4546):1306496412025 1306496387535
十一月五号日至27日:40:12.211:DEBUG / NOPSA-P(4546):1306496412198 1306496387535
十一月五号日至27日:40:12.231:DEBUG / NOPSA-P(4546):1306496409678 1306496387535
十一月五号日至27日:40:12.242:DEBUG / NOPSA-P(4546):1306496410201 1306496387535
十一月五号日至27日:40:12.251:DEBUG / NOPSA-P(4546):1306496408950 1306496387535
十一月五号日至27日:40:12.251:DEBUG / NOPSA-P(4546):1306496409878 1306496387535
十一月五号日至27日:40:12.251:DEBUG / NOPSA-P(4546):1306496410037 1306496387535
十一月五号日至27日:40:12.261:DEBUG / NOPSA-P(4546):1306496408214 1306496387535
十一月五号日至27日:40:12.311:DEBUG / NOPSA-P(4546):1306496405988 1306496387535
十一月五号日至27日:40:12.341:DEBUG / NOPSA-P(4546):1306496411254 1306496387535
十一月五号日至27日:40:12.371:DEBUG / NOPSA-P(4546):1306496409327 1306496387535
十一月五号日至27日:40:12.442:DEBUG / NOPSA-P(4546):1306496410398 1306496387535
十一月五号日至27日:40:12.471:DEBUG / NOPSA-P(4546):1306496412431 1306496387535
十一月五号日至27日:40:12.521:DEBUG / NOPSA-P(4546):1306496409478 1306496387535
十一月五号日至27日:40:12.553:DEBUG / NOPSA-P(4546):1306496411508 1306496387535
十一月五号日至27日:40:12.671:DEBUG / NOPSA-P(4546):1306496412639 1306496387535
十一月五号日至27日:40:12.711:DEBUG / NOPSA-P(4546):1306496410566 1306496387535
十一月五号日至27日:40:12.841:DEBUG / NOPSA-P(4546):1306496412813 1306496387535
十一月五号日至27日:40:12.891:DEBUG / NOPSA-P(4546):1306496411865 1306496387535
十一月五号日至27日:40:13.001:DEBUG / NOPSA-P(4546):1306496412983 1306496387535
十一月五号日至27日:40:13.051:DEBUG / NOPSA-P(4546):1306496412025 1306496387535
十一月五号日至27日:40:13.193:DEBUG / NOPSA-P(4546):1306496413166 1306496387535
十一月五号日至27日:40:13.231:DEBUG / NOPSA-P(4546):1306496409678 1306496387535
十一月五号日至27日:40:13.251:DEBUG / NOPSA-P(4546):1306496410201 1306496387535
十一月五号日至27日:40:13.251:DEBUG / NOPSA-P(4546):1306496409878 1306496387535
十一月五号日至27日:40:13.251:DEBUG / NOPSA-P(4546):1306496410037 1306496387535
十一月五号日至27日:40:13.251:DEBUG / NOPSA-P(4546):1306496408950 1306496387535
十一月五号日至27日:40:13.261:DEBUG / NOPSA-P(4546):1306496408214 1306496387535
十一月五号日至27日:40:132.71:DEBUG / NOPSA-P(4546):1306496412198 1306496387535
十一月五号日至27日:40:13.321:DEBUG / NOPSA-P(4546):1306496405988 1306496387535
十一月五号日至27日:40:13.341:DEBUG / NOPSA-P(4546):1306496411254 1306496387535
十一月五号日至27日:40:13.371:DEBUG / NOPSA-P(4546):1306496409327 1306496387535
十一月五号日至27日:40:13.431:DEBUG / NOPSA-P(4546):1306496413405 1306496387535
十一月五号日至27日:40:13.441:DEBUG / NOPSA-P(4546):1306496410398 1306496387535
十一月五号日至27日:40:13.481:DEBUG / NOPSA-P(4546):1306496412431 1306496387535
十一月五号日至27日:40:13.532:DEBUG / NOPSA-P(4546):1306496409478 1306496387535
 

这是最新的code。 gameOn 是一个布尔值,现在它是真实的。

 私人无效startGameTimeElapseThread(){
    如果(gameOn){
        新主题(新的Runnable(){
            日期D =新的日期();
            公共无效的run(){

                    Log.d(TAG,+ d.getTime()+毫秒+ d.getTime()/ 1000+秒);
                    postInvalidate(795,150,1024,300);
                    android.os.SystemClock.sleep(1000);
                    startGameTimeElapseThread();

            }
        })。开始();
    }
}
 

输出为

 十二月五号至27日:00:51.211:DEBUG / NOPSA-P(5098):1306497650761ms 1306497650sec
12月5号至27日:00:51.211:DEBUG / NOPSA-P(5098):1306497650786ms 1306497650sec
12月5号至27日:00:51.221:DEBUG / NOPSA-P(5098):1306497650764ms 1306497650sec
12月5号至27日:00:51.221:DEBUG / NOPSA-P(5098):1306497650763ms 1306497650sec
12月5号至27日:00:51.221:DEBUG / NOPSA-P(5098):1306497650769ms 1306497650sec
12月5号至27日:00:51.231:DEBUG / NOPSA-P(5098):1306497650749ms 1306497650sec
12月5号至27日:00:51.231:DEBUG / NOPSA-P(5098):1306497650736ms 1306497650sec
12月5号至27日:00:51.231:DEBUG / NOPSA-P(5098):1306497650742ms 1306497650sec
12月5号至27日:00:51.241:DEBUG / NOPSA-P(5098):1306497650746ms 1306497650sec
12月5号至27日:00:51.241:DEBUG / NOPSA-P(5098):1306497650848ms 1306497650sec
12月5号至27日:00:51.251:DEBUG / NOPSA-P(5098):1306497650729ms 1306497650sec
12月5号至27日:00:51.271:DEBUG / NOPSA-P(5098):1306497650739ms 1306497650sec
12月5号至27日:00:51.271:DEBUG / NOPSA-P(5098):1306497650739ms 1306497650sec
12月5号至27日:00:51.271:DEBUG / NOPSA-P(5098):1306497650868ms 1306497650sec
12月5号至27日:00:51.271:DEBUG / NOPSA-P(5098):1306497650798ms 1306497650sec
12月5号至27日:00:51.281:DEBUG / NOPSA-P(5098):1306497650870ms 1306497650sec
12月5号至27日:00:51.291:DEBUG / NOPSA-P(5098):1306497651020ms 1306497651sec
12月5号至27日:00:51.551:DEBUG / NOPSA-P(5098):1306497651498ms 1306497651sec
12月5号至27日:00:51.551:DEBUG / NOPSA-P(5098):1306497651502ms 1306497651sec
12月5号至27日:00:51.642:DEBUG / NOPSA-P(5098):1306497651523ms 1306497651sec
12月5号至27日:00:51.651:DEBUG / NOPSA-P(5098):1306497651537ms 1306497651sec
12月5号至27日:00:51.691:DEBUG / NOPSA-P(5098):1306497651529ms 1306497651sec
12月5号至27日:00:51.701:DEBUG / NOPSA-P(5098):1306497651534ms 1306497651sec
12月5号至27日:00:51.784:DEBUG / NOPSA-P(5098):1306497651527ms 1306497651sec
12月5号至27日:00:51.801:DEBUG / NOPSA-P(5098):1306497651570ms 1306497651sec
12月5号至27日:00:51.801:DEBUG / NOPSA-P(5098):1306497651564ms 1306497651sec
12月5号至27日:00:51.891:DEBUG / NOPSA-P(5098):1306497651682ms 1306497651sec
12月5号至27日:00:51.891:DEBUG / NOPSA-P(5098):1306497651690ms 1306497651sec
12月5号至27日:00:51.891:DEBUG / NOPSA-P(5098):1306497651685ms 1306497651sec
12月5号至27日:00:51.901:DEBUG / NOPSA-P(5098):1306497651693ms 1306497651sec
12月5号至27日:00:51.914:DEBUG / NOPSA-P(5098):1306497651647ms 1306497651sec
12月5号至27日:00:51.914:DEBUG / NOPSA-P(5098):1306497651667ms 1306497651sec
12月5号至27日:00:51.921:DEBUG / NOPSA-P(5098):1306497651666ms 1306497651sec
12月5号至27日:00:51.921:DEBUG / NOPSA-P(5098):1306497651658ms 1306497651sec
12月5号至27日:00:51.921:DEBUG / NOPSA-P(5098):1306497651663ms 1306497651sec
12月5号至27日:00:51.932:DEBUG / NOPSA-P(5098):1306497651688ms 1306497651sec
12月5号至27日:00:51.941:DEBUG / NOPSA-P(5098):1306497651711ms 1306497651sec
12月5号至27日:00:51.961:DEBUG / NOPSA-P(5098):1306497651792ms 1306497651sec
12月5号至27日:00:51.971:DEBUG / NOPSA-P(5098):1306497651629ms 1306497651sec
12月5号至27日:00:51.981:DEBUG / NOPSA-P(5098):1306497651714ms 1306497651sec
12月5号至27日:00:52.083:DEBUG / NOPSA-P(5098):1306497652048ms 1306497652sec
 

解决方案

您需要的<一个href="http://developer.android.com/reference/java/lang/Thread.html#sleep%28long%29"><$c$c>sleep类的方法。

  

公共静态无效睡眠(时间长)

     

原因而发送该消息睡觉的时间给定的间隔(以毫秒为单位)的线程。在precision不能保证 - 线程可能睡眠多于或少于要求

     

参数

     

时间以毫秒为单位睡觉的时间。

private void startGameTimeElapseThread(){
    new Thread(new Runnable() {
        Date d = new Date();
        public void run() {
            while (gameOn){
                Log.d(TAG,""+d.getTime()+" "+gameStatus.getLastTimeUpdated());

                postInvalidate(795, 150, 1024, 300);
                try {
                    synchronized (this) {
                        wait(1000); 
                    }
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "Waiting didnt work!!");
                    e.printStackTrace();
                }
            }
        }
    }).start();
}

Here I wanted to make call the "Log.d" and "postInvalidate" every one second. But when i check it from LogCat it seems loop runs faster than i want it to be. Why doesnt this loop just wait for 1000ms ?

Following are the output in LogCat. So you can see its not sleeping for a 1 second at all. I used Thread.sleep as well ( after you suggesting )

05-27 11:40:10.060: DEBUG/NOPSA-P(4546): 1306496408950 1306496387535
05-27 11:40:10.070: DEBUG/NOPSA-P(4546): 1306496410037 1306496387535
05-27 11:40:10.232: DEBUG/NOPSA-P(4546): 1306496410201 1306496387535
05-27 11:40:10.250: DEBUG/NOPSA-P(4546): 1306496408214 1306496387535
05-27 11:40:10.310: DEBUG/NOPSA-P(4546): 1306496405988 1306496387535
05-27 11:40:10.361: DEBUG/NOPSA-P(4546): 1306496409327 1306496387535
05-27 11:40:10.431: DEBUG/NOPSA-P(4546): 1306496410398 1306496387535
05-27 11:40:10.521: DEBUG/NOPSA-P(4546): 1306496409478 1306496387535
05-27 11:40:10.593: DEBUG/NOPSA-P(4546): 1306496410566 1306496387535
05-27 11:40:11.230: DEBUG/NOPSA-P(4546): 1306496409678 1306496387535
05-27 11:40:11.230: DEBUG/NOPSA-P(4546): 1306496410201 1306496387535
05-27 11:40:11.241: DEBUG/NOPSA-P(4546): 1306496409878 1306496387535
05-27 11:40:11.241: DEBUG/NOPSA-P(4546): 1306496410037 1306496387535
05-27 11:40:11.241: DEBUG/NOPSA-P(4546): 1306496408950 1306496387535
05-27 11:40:11.260: DEBUG/NOPSA-P(4546): 1306496408214 1306496387535
05-27 11:40:11.314: DEBUG/NOPSA-P(4546): 1306496405988 1306496387535
05-27 11:40:11.314: DEBUG/NOPSA-P(4546): 1306496411254 1306496387535
05-27 11:40:11.361: DEBUG/NOPSA-P(4546): 1306496409327 1306496387535
05-27 11:40:11.431: DEBUG/NOPSA-P(4546): 1306496410398 1306496387535
05-27 11:40:11.520: DEBUG/NOPSA-P(4546): 1306496409478 1306496387535
05-27 11:40:11.551: DEBUG/NOPSA-P(4546): 1306496411508 1306496387535
05-27 11:40:11.712: DEBUG/NOPSA-P(4546): 1306496410566 1306496387535
05-27 11:40:11.881: DEBUG/NOPSA-P(4546): 1306496411865 1306496387535
05-27 11:40:12.051: DEBUG/NOPSA-P(4546): 1306496412025 1306496387535
05-27 11:40:12.211: DEBUG/NOPSA-P(4546): 1306496412198 1306496387535
05-27 11:40:12.231: DEBUG/NOPSA-P(4546): 1306496409678 1306496387535
05-27 11:40:12.242: DEBUG/NOPSA-P(4546): 1306496410201 1306496387535
05-27 11:40:12.251: DEBUG/NOPSA-P(4546): 1306496408950 1306496387535
05-27 11:40:12.251: DEBUG/NOPSA-P(4546): 1306496409878 1306496387535
05-27 11:40:12.251: DEBUG/NOPSA-P(4546): 1306496410037 1306496387535
05-27 11:40:12.261: DEBUG/NOPSA-P(4546): 1306496408214 1306496387535
05-27 11:40:12.311: DEBUG/NOPSA-P(4546): 1306496405988 1306496387535
05-27 11:40:12.341: DEBUG/NOPSA-P(4546): 1306496411254 1306496387535
05-27 11:40:12.371: DEBUG/NOPSA-P(4546): 1306496409327 1306496387535
05-27 11:40:12.442: DEBUG/NOPSA-P(4546): 1306496410398 1306496387535
05-27 11:40:12.471: DEBUG/NOPSA-P(4546): 1306496412431 1306496387535
05-27 11:40:12.521: DEBUG/NOPSA-P(4546): 1306496409478 1306496387535
05-27 11:40:12.553: DEBUG/NOPSA-P(4546): 1306496411508 1306496387535
05-27 11:40:12.671: DEBUG/NOPSA-P(4546): 1306496412639 1306496387535
05-27 11:40:12.711: DEBUG/NOPSA-P(4546): 1306496410566 1306496387535
05-27 11:40:12.841: DEBUG/NOPSA-P(4546): 1306496412813 1306496387535
05-27 11:40:12.891: DEBUG/NOPSA-P(4546): 1306496411865 1306496387535
05-27 11:40:13.001: DEBUG/NOPSA-P(4546): 1306496412983 1306496387535
05-27 11:40:13.051: DEBUG/NOPSA-P(4546): 1306496412025 1306496387535
05-27 11:40:13.193: DEBUG/NOPSA-P(4546): 1306496413166 1306496387535
05-27 11:40:13.231: DEBUG/NOPSA-P(4546): 1306496409678 1306496387535
05-27 11:40:13.251: DEBUG/NOPSA-P(4546): 1306496410201 1306496387535
05-27 11:40:13.251: DEBUG/NOPSA-P(4546): 1306496409878 1306496387535
05-27 11:40:13.251: DEBUG/NOPSA-P(4546): 1306496410037 1306496387535
05-27 11:40:13.251: DEBUG/NOPSA-P(4546): 1306496408950 1306496387535
05-27 11:40:13.261: DEBUG/NOPSA-P(4546): 1306496408214 1306496387535
05-27 11:40:13.271: DEBUG/NOPSA-P(4546): 1306496412198 1306496387535
05-27 11:40:13.321: DEBUG/NOPSA-P(4546): 1306496405988 1306496387535
05-27 11:40:13.341: DEBUG/NOPSA-P(4546): 1306496411254 1306496387535
05-27 11:40:13.371: DEBUG/NOPSA-P(4546): 1306496409327 1306496387535
05-27 11:40:13.431: DEBUG/NOPSA-P(4546): 1306496413405 1306496387535
05-27 11:40:13.441: DEBUG/NOPSA-P(4546): 1306496410398 1306496387535
05-27 11:40:13.481: DEBUG/NOPSA-P(4546): 1306496412431 1306496387535
05-27 11:40:13.532: DEBUG/NOPSA-P(4546): 1306496409478 1306496387535

This is the latest Code. gameOn is a boolean, for now it's true.

private void startGameTimeElapseThread(){
    if (gameOn){
        new Thread(new Runnable() {
            Date d = new Date();
            public void run() {

                    Log.d(TAG,""+d.getTime()+"ms  "+d.getTime()/1000+"sec");
                    postInvalidate(795, 150, 1024, 300);
                    android.os.SystemClock.sleep(1000); 
                    startGameTimeElapseThread();

            }
        }).start();
    }
}

The output is

05-27 12:00:51.211: DEBUG/NOPSA-P(5098): 1306497650761ms  1306497650sec
05-27 12:00:51.211: DEBUG/NOPSA-P(5098): 1306497650786ms  1306497650sec
05-27 12:00:51.221: DEBUG/NOPSA-P(5098): 1306497650764ms  1306497650sec
05-27 12:00:51.221: DEBUG/NOPSA-P(5098): 1306497650763ms  1306497650sec
05-27 12:00:51.221: DEBUG/NOPSA-P(5098): 1306497650769ms  1306497650sec
05-27 12:00:51.231: DEBUG/NOPSA-P(5098): 1306497650749ms  1306497650sec
05-27 12:00:51.231: DEBUG/NOPSA-P(5098): 1306497650736ms  1306497650sec
05-27 12:00:51.231: DEBUG/NOPSA-P(5098): 1306497650742ms  1306497650sec
05-27 12:00:51.241: DEBUG/NOPSA-P(5098): 1306497650746ms  1306497650sec
05-27 12:00:51.241: DEBUG/NOPSA-P(5098): 1306497650848ms  1306497650sec
05-27 12:00:51.251: DEBUG/NOPSA-P(5098): 1306497650729ms  1306497650sec
05-27 12:00:51.271: DEBUG/NOPSA-P(5098): 1306497650739ms  1306497650sec
05-27 12:00:51.271: DEBUG/NOPSA-P(5098): 1306497650739ms  1306497650sec
05-27 12:00:51.271: DEBUG/NOPSA-P(5098): 1306497650868ms  1306497650sec
05-27 12:00:51.271: DEBUG/NOPSA-P(5098): 1306497650798ms  1306497650sec
05-27 12:00:51.281: DEBUG/NOPSA-P(5098): 1306497650870ms  1306497650sec
05-27 12:00:51.291: DEBUG/NOPSA-P(5098): 1306497651020ms  1306497651sec
05-27 12:00:51.551: DEBUG/NOPSA-P(5098): 1306497651498ms  1306497651sec
05-27 12:00:51.551: DEBUG/NOPSA-P(5098): 1306497651502ms  1306497651sec
05-27 12:00:51.642: DEBUG/NOPSA-P(5098): 1306497651523ms  1306497651sec
05-27 12:00:51.651: DEBUG/NOPSA-P(5098): 1306497651537ms  1306497651sec
05-27 12:00:51.691: DEBUG/NOPSA-P(5098): 1306497651529ms  1306497651sec
05-27 12:00:51.701: DEBUG/NOPSA-P(5098): 1306497651534ms  1306497651sec
05-27 12:00:51.784: DEBUG/NOPSA-P(5098): 1306497651527ms  1306497651sec
05-27 12:00:51.801: DEBUG/NOPSA-P(5098): 1306497651570ms  1306497651sec
05-27 12:00:51.801: DEBUG/NOPSA-P(5098): 1306497651564ms  1306497651sec
05-27 12:00:51.891: DEBUG/NOPSA-P(5098): 1306497651682ms  1306497651sec
05-27 12:00:51.891: DEBUG/NOPSA-P(5098): 1306497651690ms  1306497651sec
05-27 12:00:51.891: DEBUG/NOPSA-P(5098): 1306497651685ms  1306497651sec
05-27 12:00:51.901: DEBUG/NOPSA-P(5098): 1306497651693ms  1306497651sec
05-27 12:00:51.914: DEBUG/NOPSA-P(5098): 1306497651647ms  1306497651sec
05-27 12:00:51.914: DEBUG/NOPSA-P(5098): 1306497651667ms  1306497651sec
05-27 12:00:51.921: DEBUG/NOPSA-P(5098): 1306497651666ms  1306497651sec
05-27 12:00:51.921: DEBUG/NOPSA-P(5098): 1306497651658ms  1306497651sec
05-27 12:00:51.921: DEBUG/NOPSA-P(5098): 1306497651663ms  1306497651sec
05-27 12:00:51.932: DEBUG/NOPSA-P(5098): 1306497651688ms  1306497651sec
05-27 12:00:51.941: DEBUG/NOPSA-P(5098): 1306497651711ms  1306497651sec
05-27 12:00:51.961: DEBUG/NOPSA-P(5098): 1306497651792ms  1306497651sec
05-27 12:00:51.971: DEBUG/NOPSA-P(5098): 1306497651629ms  1306497651sec
05-27 12:00:51.981: DEBUG/NOPSA-P(5098): 1306497651714ms  1306497651sec
05-27 12:00:52.083: DEBUG/NOPSA-P(5098): 1306497652048ms  1306497652sec

解决方案

You need the sleep method of the Thread class.

public static void sleep (long time)

Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.

Parameters

time The time to sleep in milliseconds.

这篇关于如何与QUOT;等待&QUOT;在Android的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆