如何加载新的线程AdMob的广告? [英] How to load admob ads in new thread?

查看:446
本文介绍了如何加载新的线程AdMob的广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我返工我的应用程序为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?

这篇关于如何加载新的线程AdMob的广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆