AdMob-更好的Android活动性能 [英] AdMob - better performance in android activity

查看:111
本文介绍了AdMob-更好的Android活动性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现AdMob广告的Android应用程序。

I have android application where I implemented AdMob ads.

我的布局代码非常简单-将AdView添加到LinearLayout中:

My layout code is very simple - added AdView into LinearLayout:

<com.google.ads.AdView
    android:id="@+id/adMob1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="{AdID}" />

在MyActivity中,我正在调用onCreate()方法:

In MyActivity in onCreate() method I am calling:

    boolean showAdds = true;
    if(this.showAdds) {
        AdView adView = (AdView) findViewById(R.id.adMob1);
        adView.loadAd(new AdRequest());
    }

在AdMob之后在某些较旧的android设备上(例如在Samsung Galaxy S1上测试)实施该应用程序非常非常慢。但是,当我将 showAdds变量设置为 false-> MyActivity的加载要好得多。

On some older android devices (tested for example on Samsung Galaxy S1) after AdMob implementation the app is very very slow. But when I set "showAdds" variable to "false" -> the loading of MyActivity is much better.

是否有可能使带有admob的应用程序更快?

Is there any possibility to make the application with admob faster?

感谢您的所有评论。

推荐答案

我也一直在努力随着AdView增加应用程序加载时间。我的解决方案是将广告代码移入延迟处理程序(在onCreate内)…

I too have been struggling with AdView increasing app load time. My solution was to move the ad code into a delay handler (within onCreate)…

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
     AdRequest adRequest = new AdRequest.Builder().build();
     adView.loadAd(adRequest);
     adView.bringToFront();
  }
}, 5000);

所以现在应用程序快速启动,然后在5秒后加载adview。 (使用p.s.bringToFront是因为我的应用布局使用了XML和代码的混合形式,因此这可以防止adView被隐藏)

So now the app starts quickly and then after 5s the adview is loaded. (p.s. .bringToFront is used because my app layout uses a mixture of XML and code, so this stops adView from being hidden)

这篇关于AdMob-更好的Android活动性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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