如果没有互联网连接,活动就会保持黑色,就好像它正在加载一样。如何确保活动首先加载?
答案 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();