I rework my application for Android ICS and encountered the following problem. Ads are downloaded in oncreate in main thread, so the article (which is displayed by the webview) does not appear until the ads will not load.
How to load ads in new thread?
Here is the code of WebView Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock_Light);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
showActionBar();
adView = (AdView) findViewById(R.id.adView);
adView.setAdListener(this);
....
}
....
@Override
public void onDismissScreen(Ad arg0) {
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
ads_view.setVisibility(View.GONE);
}
@Override
public void onLeaveApplication(Ad arg0) {
}
@Override
public void onPresentScreen(Ad arg0) {
}
@Override
public void onReceiveAd(Ad arg0) {
ads_view.setVisibility(View.VISIBLE);
}
Also I put adView block in RelativeLayout with id “ads_view”.
This method doesn’t work:
adView = (AdView) findViewById(R.id.adView);
adView.setAdListener(this);
(new Thread() {
public void run() {
Looper.prepare();
adView.loadAd(new AdRequest());
}
}).start();
Help, please.
The loadAd call needs to happen on the UI thread, because the SDK will eventually be adding the to your view hierarchy.
Does your application have a WebView that is not displaying until an ad is received? What does your layout look like? Are you by any chance setting the article’s view to NONE until you get an ad?