加入AdMob的广告到Android应用程序的每一个画面 [英] Add AdMob Advertise to each and every Screen of Android App

查看:129
本文介绍了加入AdMob的广告到Android应用程序的每一个画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够加载AdMob的加用以下code到应用程序的第一个屏幕(活动)。

I am able to load the AdMob add using following code into the very first screen (Activity) of the application.

@Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
        View next = findViewById(R.id.next);
        OnClickListener onClickListener = new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(BannerEssentials.this, NextActivity.class));
            }
        };
        next.setOnClickListener(onClickListener);

        AdView adView = new AdView(this, AdSize.BANNER, "");
        layout.addView(adView);
        AdRequest request = new AdRequest();
        request.addTestDevice(AdRequest.TEST_EMULATOR);
        adView.loadAd(request);            
    }

下一屏幕(活动)涉及到前台pressing Next(下一步)按钮后,但广告并没有出现在这个屏幕上。

The next screen (Activity) comes to foreground after pressing the Next button; but the advertise does not appear on this screen.

有没有(简单)的方式来增加AdMob的添加到每个应用程序了和每个屏幕(活动)?

Is there any (easy) way to add AdMob add to each and every screen(Activity) of the applicaiton?

推荐答案

创建一个超类,并集中所有的相关的AdMob code至受保护的方法:

Create a super class and centralize all your admob related code into a protected method:

public class AdmobActivity extends Activity {
  ... ...

  protected void showAds(View root) {
    AdView adView = new AdView(this, AdSize.BANNER, "");
    root.addView(adView);
    AdRequest request = new AdRequest();
    request.addTestDevice(AdRequest.TEST_EMULATOR);
    adView.loadAd(request); 
  }

... ...
}

对于所有的活动需要显示广告,扩展AdmobActivity和Acticity.onCreate正确地调用showAds()()方法。

For all your activities that need show ads, extends AdmobActivity and call showAds() properly in Acticity.onCreate() method.

希望有帮助。

这篇关于加入AdMob的广告到Android应用程序的每一个画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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