Can I load admob ad using AsyncTask ?
I have tried it but I get lots of warning at runtime and the ad is not loaded
one of the warning when I create new AdView instance is
07-06 09:57:31.170: W/webview(1113): java.lang.Throwable: Warning: A WebView method was called on thread 'AsyncTask #1'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
my method looks like this
@Override
protected AdView doInBackground(Activity... activityParam)
{
Looper.prepare();
activity = activityParam[0];
// Create the adView
AdView adView = new AdView(activity, AdSize.BANNER, "xxxxxxxxxxxxx");
return adView;
}
Please advise if this should at all be called on non UI thread, the only reason I am doing it to prevent UI blocking..
Edit.
May be I did not express my problem properly,
I am trying to load the ad in background because it seems to block for some seconds,
I do not want to block my activity’s interface.
read this post How to avoid Admob blocking the UI thread where it is recommended that to avoid UI blocking one should use AsyncTask
So what I want to know if is alternate to load an ad in the background.. ?
Separate out the time required to create the AdView which needs to be done on the UI thread and the time it takes to communicate to the ad server and deliver an ad. The ‘block’ or ‘lag’ is probably the Ad SDK’s thread trying to get an ad to show to you. As it has to do this over the internet it takes time for an ad to show up. I really don’t think AdMob would block the UI thread while trying to get an ad, however there will be a visible delay between when you see all of your UI widget items (buttons, textfields, images, etc.) shown on the screen of your activity and when the ad shows up.