如何加载新的线程AdMob的广告?线程、加载、广告、AdMob

2023-09-09 22:12:17 作者:哥姓坚名强字猖狂&

我返工我的应用程序为Android ICS和遇到以下问题。广告下载在OnCreate中在主线程,所以文章(这是由web视图显示的)不会出现,直到广告将不会加载。 如何加载广告在新线程?

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?

下面是的WebView活动的code:

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

另外,我把AD浏览报块RelativeLayout的ID为ads_view。

Also I put adView block in RelativeLayout with id "ads_view".

这个方法不起作用:

adView = (AdView) findViewById(R.id.adView);
        adView.setAdListener(this);

        (new Thread() {
            public void run() {
                 Looper.prepare();
                adView.loadAd(new AdRequest());
            }
        }).start();

帮助,请。

推荐答案

在loadAd调用需要发生在UI线程上,因为SDK最终将被添加到您的视图层次结构。

The loadAd call needs to happen on the UI thread, because the SDK will eventually be adding the to your view hierarchy.

应用程序是否有未显示直到接收到广告中的WebView?什么是你的布局是什么样子?你任何机会文章的观点设置为NONE,直到你得到的广告?

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?

 
精彩推荐
图片推荐