gpt4 book ai didi

android - Admob 导致应用加载,但不显示

转载 作者:行者123 更新时间:2023-11-29 14:07:05 25 4
gpt4 key购买 nike

当我的应用程序中存在 admob 时,主布局(有时)根本不会显示。其他时候它开始就好了。我遇到这个间歇性问题已有一段时间了,无法找到解决方法。我确定它与获取广告(或缺少广告)有关。当我在 admob 中启用 Google adsense 以及“成人”广告时,该应用程序运行良好并加载了这些广告。如果我从我的应用程序中删除 ad mob,该应用程序启动正常。它会随机显示一个空白屏幕并且永远不会加载任何按钮和其他时间加载带有广告的所有按钮。有什么想法吗?

这是我的索引 Activity :

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView adView = (AdView)this.findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
backCheck = 0;
}

main.xml 只有 10 个按钮和广告……没什么特别的。但它只会坐在那里并显示一个空白屏幕(似乎无法获取广告。)

我在 logcat 上的唯一信息是...

06-02 19:45:10.923: INFO/Ads(264): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
06-02 19:45:11.053: WARN/Ads(264): loadAd called while the ad is already loading.
06-02 19:45:12.033: INFO/ARMAssembler(64): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x451220:0x4512c4] in 2310362 ns
06-02 19:45:12.323: INFO/ActivityManager(64): Displayed activity com.robores.elect/.Index: 3500 ms (total 3500 ms)
06-02 19:45:12.453: INFO/Ads(264): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"slotname":"a14dd7f0258a8b7","u_w":320,"msid":"com.robores.elect","simulator":1,"cap":"m,a","js":"afma-sdk-a-v4.1.0","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","net":"ed","app_name":"1.android.com.robores.elect","hl":"en","u_h":533,"u_audio":4,"u_so":"p"});</script></head><body></body></html>
06-02 19:45:14.573: INFO/Ads(264): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=a14dd7f0258a8b7&u_w=320&msid=com.robores.elect&cap=m%2Ca&js=afma-sdk-a-v4.1.0&isu=B3EEABB8EE11C2BE770B684D95219ECB&format=320x50_mb&net=ed&app_name=1.android.com.robores.elect&hl=en&u_h=533&u_audio=4&u_so=p&output=html&region=mobile_app&u_tz=0&ex=1&client_sdk=1", "afmaNotifyDt": "null">
06-02 19:45:16.573: WARN/webcore(264): Can't get the viewWidth after the first layout
06-02 19:45:16.693: DEBUG/dalvikvm(264): GC freed 3551 objects / 299672 bytes in 100ms
06-02 19:45:16.753: DEBUG/webviewglue(264): nativeDestroy view: 0x365538
06-02 19:45:16.763: ERROR/webcoreglue(264): The real object has been deleted
06-02 19:45:17.075: INFO/Ads(264): onReceiveAd()

最佳答案

AdView adView = (AdView)findById(R.id.adview1);
(new Thread() {
public void run() {
Looper.prepare();
adView.loadAd(new AdRequest());
}
}).start();

将以上代码放在Activity的onCreate中!!

在单独的线程中而不是在主线程中加载广告!!

关于android - Admob 导致应用加载,但不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6219689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com