在广告首先加载之前,不会加载活动。如何在admob广告之前首先加载活动

时间:2012-10-11 07:51:43

标签: android admob

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

1 个答案:

答案 0 :(得分: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();