How to make an inter-page ad when clicking on a button? Below is the code. Where are the mistakes made? Did according to the instructions of Admob. Please correct.

public class MainActivity extends AppCompatActivity { InterstitialAd mInterstitialAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId("ca-app-pub-9777249340958310/3008582982"); requestNewInterstitial (); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { requestNewInterstitial(); } }); } private void requestNewInterstitial() { requestNewInterstitial(); } public void onClick(View view) { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { } } } 
  • one
    There were errors in formatting the issue. :) Next time select the entire code and press Ctrl + K or {} button - Nick Volynkin
  • Ok, thanks, I will know. - anarbus
  • On the merits, unfortunately, I will not tell you anything. - Nick Volynkin

1 answer 1

You have 2 problems:

  1. Judging by the code, your requestNewInterstitial() method simply calls itself, doing nothing at all.
  2. You are nowhere (judging by the code) are not requesting, in fact, advertising from the server.

Total, according to the documentation you need (for example, inside the requestNewInterstitial() method) add the code that loads the advertisement.

 //Создаём запрос серверу рекламы AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); //тут желательно добавить девайс в список тестовых, дабы не нарваться на бан //за показ рекламы самому себе //Начинаем загрузку рекламы mInterstitialAd.loadAd(adRequestBuilder.build());