我可以使用AsyncTask加载admob广告吗?Admob不能与AsyncTask合作
我都尝试过,但我得到很多的警告,在运行时和广告未加载
的警告,当我创建新的AdView实例
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.
我的方法是这样的
一个@Override
protected AdView doInBackground(Activity... activityParam)
{
Looper.prepare();
activity = activityParam[0];
// Create the adView
AdView adView = new AdView(activity, AdSize.BANNER, "xxxxxxxxxxxxx");
return adView;
}
请告知,如果这应该在所有非UI线程调用,唯一的原因,我这样做,以避免阻塞UI ..
编辑。
可能是我没有正确表达我的问题,
我试图加载背景的广告,因为它似乎阻止几秒钟, 我不想阻止我的活动界面。
阅读这篇文章How to avoid Admob blocking the UI thread其中建议,以避免阻塞UI应该使用的AsyncTask
所以我想知道,如果是交替在后台加载广告的..?
我只是按照示例,并在UI线程中添加adview,而不是把它放在一个AsyncTask。 – 2012-07-06 05:08:50
@MorrisonChang我做到了这一点,但后来我看到了一些滞后,然后我在我的问题中提到的帖子显示了哪些建议在AsyncTask上完成 – Ahmed 2012-07-06 05:22:06