如何使横幅广告(AdMob的)适用于所有我的活动 [英] How do I make Banners Ads (admob) Common for All My Activities

查看:153
本文介绍了如何使横幅广告(AdMob的)适用于所有我的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三项活动,所有这三项活动有横幅广告,因为他们由code。在三的的OnCreate()方法设置底部活动。

I have about three Activities, and all these three activities have Banner ads at the bottom which are set by code in the OnCreate() method of the Three Activities.

和由于某些原因,我需要完成每一项活动,同时从一种活动转移到其他,和 startActivity()的回来的第一个活动。

And due to some reason I need to Finish each Activity while moving from one activity to the other, and startActivity() for coming back to the first Activity.

我想知道,我怎么做只有一个横幅广告这三个活动,而不是从不同的单独调用它们的onCreate ,因为我的疑问是,在过渡活动我是令人耳目一新的广告(安静ofently),这是不是你点击一个很好的做法。

I wanted to know, how do i make just one Banner Ad for all these three Activity instead of calling them individually from different onCreate, because my doubt is that on transition of Activities I am refreshing Ads(quiet ofently) which isn't a good practice for your clicks.

我应该在静态类中声明,以便它可以从任何活动被调用,只是一个实例会在那里(所以没有令人耳目一新由于活动创造)

Should I declare it in a static Class so that it can be called from any activity and just one instance would be there(so no refreshing due to activity creation)

建议,欢迎。

推荐答案

你知道有关实施ViewStub?

Do you know about implementing ViewStub?

有关您的问题,ViewStub用来放置AdMob的广告位于页脚,你只需要创建布局页脚中,然后用ViewStub例子包括在XML布局(活动布局)此布局

For your problem, ViewStub is used to place AdMob ads at Footer, you just have to create layout for this Footer and then include this layout in your XML layouts (activity layouts) by using ViewStub example.

下面是一个 示例 实施ViewStub,是它的标题栏,但你可以从它采取的理念。

Here is an example for implementing ViewStub, yes its for Title bar but you can take concept from it.

现在,优化的解决方案(code),你可以创建一个摘要类和延伸活动类,并包括这里面的AdMob的广告code类。

Now, to optimize solution (code), you can create an Abstract class and extends Activity class and include your AdMob ads code inside this class.

例如:

public abstract class BaseActivity extends Activity
{
   /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

        public void setFooterAds()
        {
              // Make ViewStub visible
              // include your Ads code
        }
}

现在,您只需要扩展这个BaseActivity类的活动课,并调用setFooterAds()方法来显示AdMob的广告。

这篇关于如何使横幅广告(AdMob的)适用于所有我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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