import androID.app.Activity;import androID.os.Bundle;import androID.util.Log;import androID.Widget.Toast;import com.Google.androID.gms.ads.AdListener;import com.Google.androID.gms.ads.AdRequest;import com.Google.androID.gms.ads.InterstitialAd;public class Banner extends Activity {/** * Your ad unit ID,you must replace it with your actual ad unit ID Which * you can generate from Admob website * */private static final String AD_UNIT_ID = "MY ADD UNIT ID";private static final String TAG = "ExampleActivity";private InterstitialAd iAd;@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.banner); iAd = new InterstitialAd(this); iAd.setAdUnitID(AD_UNIT_ID); iAd.setAdListener(new AdListener() { @OverrIDe public voID onAdLoaded() { Log.d(TAG,"onAdLoaded"); Toast.makeText(Banner.this,"Ad loaded successfully",Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onAdFailedToload(int errorCode) { String errorMessage = String.format("Failed to load add : " + getErrorReason(errorCode)); Log.d(TAG,errorMessage); Toast.makeText(Banner.this,errorMessage,Toast.LENGTH_SHORT).show(); } }); loadInterstitial();}public voID loadInterstitial() { AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMulATOR) .addTestDevice( "You can add you device ID here,run code once and get ID from logs") .build(); iAd.loadAd(adRequest);}public voID showInterstitial() { if (iAd.isLoaded()) { iAd.show(); } else { Log.d(TAG,"Interstitial ad is not loaded yet"); }}/** * Gets a string error reason from an error code * * @param errorCode * @return */private String getErrorReason(int errorCode) { String errorReason = "unkNown error"; switch (errorCode) { case AdRequest.ERROR_CODE_INTERNAL_ERROR: errorReason = "internal error"; break; case AdRequest.ERROR_CODE_INVALID_REQUEST: errorReason = "invalID request"; break; case AdRequest.ERROR_CODE_NETWORK_ERROR: errorReason = "network Error"; break; case AdRequest.ERROR_CODE_NO_FILL: errorReason = "no fill"; break; } return errorReason;}@OverrIDeprotected voID onDestroy() { showInterstitial(); super.onDestroy();}
}
插页式广告加载成功,但我得到一个这样的空白屏幕(我等了1-2分钟,但仍然没有广告节目):
我仔细检查了我的AD_UNIT_ID.可能是什么问题呢?这是正常的吗?我还处于开发阶段,所以当我在Play商店上传我的应用程序时,这会得到纠正吗?
解决方法 你永远不会让这个工作.在您的活动被销毁时,插页式广告没有上下文.而是在您的应用中找到一个自然断点,然后显示插页式广告.
总结以上是内存溢出为你收集整理的android-activity – Admob插页式加载但显示空屏幕全部内容,希望文章能够帮你解决android-activity – Admob插页式加载但显示空屏幕所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)