我为Android创建了一个简单的棋盘游戏,我在游戏结束后遇到了广告问题。我用这个简单的功能
public void afterEnd(){
showInterstitial(); //dixnei tin diafimisi
goToNextLevel(); //paei sto ending PRIN tin diafimisi gia na min fenete periergo
}
要显示广告,然后转到下一个活动。事情就是广告从未出现过。游戏继续进行下一个活动,只有当玩家按下手机上的后退键才能转到上一个屏幕时,广告才会显示。
我的另外两个功能是:
private void showInterstitial() {
if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
private void goToNextLevel() {
startActivity(new Intent(getApplicationContext(), ScoreScreen.class));
finish();
}
如果您想要任何其他代码,请随时告诉我。
广告的生命周期中有许多事件。您可以通过AdListener类侦听这些事件。调用goToNextLevel()方法onAdClosed()方法。检查此codeSnippet以便更好地理解。
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
goToNextLevel()
}
});