检测网络及启动画面

new Thread(new Runnable() {
            @Override
            public void run() {
                //记录线程开始时间
                long currentTime = System.currentTimeMillis();
                //请求网络
                //...省略代码
                //结束时间
                long stopTime = System.currentTimeMillis();
                
                //间隔时间
                long time = stopTime-currentTime;
                //间隔时间小于页面停留时间,则线程休眠,休眠时间=停留时间-已经执行代码的时间
                if (time<2000) {
                    try {
                        Thread.sleep(2000-time);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

 

posted @ 2015-04-07 08:43  guduey  阅读(103)  评论(0编辑  收藏  举报