我按照official guide's Google的建议实施了AdMob,但之后,该应用开始陷入困境。
我的自定义脚本和原始脚本都给了我相同的结果。
通过我创建AdView功能:
public View adMob_showCreateAdBanner()
{
AdView adView = new AdView( context );
RelativeLayout.LayoutParams viewLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT , RelativeLayout.LayoutParams.WRAP_CONTENT );
//viewLayoutParams.addRule( RelativeLayout.ALIGN_BOTTOM );
viewLayoutParams.addRule( RelativeLayout.CENTER_HORIZONTAL );
adView.setLayoutParams( viewLayoutParams );
adView.setAdSize( AdSize.BANNER );
adView.setAdUnitId( "ca-app-pub-3940256099942544/6300978111" );
adView.loadAd( new AdRequest.Builder().build() );
return adView;
}
以及我如何在我的活动中调用它:
( (RelativeLayout) findViewById( R.id.adSpace ) ).addView( cl_utility.adMob_showCreateAdBanner() );
我在启动画面中调用的MobileAds.initialize(this, cl_utility.adMob_getPublisherID() );
也会导致活动卡住。
LogCat确实没那么帮助......
03-02 12:34:09.405 1141-1141/? E/EGL_emulation: tid 1141: eglCreateSyncKHR(1865): error 0x3004 (EGL_BAD_ATTRIBUTE)
03-02 12:34:09.848 1505-1529/system_process E/WindowManager: Performed 6 layouts in a row. Skipping
请帮忙吗?
答案 0 :(得分:0)
问题是主要活动是Activity
而不是AppCompatActivity
。现在一切正常。
谢谢。