Admob的不工作的AsyncTask工作、Admob、AsyncTask

2023-09-09 22:10:56 作者:三个人的时光机

可以使用的AsyncTask我加载AdMob的广告?

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

当我创建新的AD浏览报实例的警告之一

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;         
}

请告知,如果这应该在所有被称为非UI线程,唯一的原因,我这样做,以prevent UI阻塞。

Please advise if this should at all be called on non UI thread, the only reason I am doing it to prevent UI blocking..

编辑。

可能是我没EX preSS我的问题妥善,

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.

阅读这篇文章如何避免Admob的阻塞UI线程其中,建议避免UI阻断一个应该使用的AsyncTask

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.. ?

推荐答案

分离出来创建需要被UI线程,它需要进行通信的广告服务器和提供广告的时间上完成的AD浏览所需要的时间。 阻止或滞后可能是广告SDK的线程试图让广告展现给你。因为它要做到这一点在互联网上花费的时间为一个广告展现出来。我真的不认为AdMob的会阻塞UI线程尝试获取广告,但也会有,当你看到你所有的UI部件项目(按钮,文本框,图像等)之间的明显的延迟显示在屏幕上你的活动和当广告出现了。

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.