0

如果没有 Internet 连接,则活动将保持黑色,就好像它正在加载一样。如何确保活动首先加载?

4

1 回答 1

0

使用线程: http: //developer.android.com/reference/java/lang/Thread.html,将其声明为全局变量:Handler mHandler = new Handler(); 然后在您需要的地方:

new Thread(new Runnable() {
    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (true) {
            try {
                //waits 10 sec. to load the admob, enough time 
                //to load the activity
                Thread.sleep(10000); 
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        // Write your code here to the admob
                    }
                });
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
}).start();
于 2012-10-11T08:08:26.037 回答