title: Interstitial Ads kotlin
body: <p>I have implemented the interstitial ads (admob) in my app, but the ads are showing after any click and right after i open my app without doing anything.</p>
  
  <p>How can show interstitial ads after x clicks and how can i hide the ad that appear when i open the app?</p>
  
  <p>sample of the app: <a href="https://drive.google.com/file/d/1x5vf6VY3mHu0S-aNnKeLQaq3FF-_9Xjx/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1x5vf6VY3mHu0S-aNnKeLQaq3FF-_9Xjx/view?usp=sharing</a></p>
  
  <p>part of mainactivity.kt:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      hasCollections = boolean(R.bool.show_collections_tab)
      val correct = if (hasCollections) 1 else 0
      lastSection = savedInstanceState?.getInt("current", correct) ?: correct
  
      setContentView(R.layout.activity_main)
  
      // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
      MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713")
      mInterstitialAd = InterstitialAd(this)
      mInterstitialAd.adUnitId = "ca-app-pub-3940256099942544/1033173712"
      mInterstitialAd.loadAd(AdRequest.Builder().build())
  
      mInterstitialAd.adListener = object: AdListener() {
          override fun onAdLoaded() {
              if (mInterstitialAd.isLoaded) {
                  mInterstitialAd.show()
              } else {
                  Log.d("TAG", "The interstitial wasn't loaded yet.")
              }
          }
      }
  
      setSupportActionBar(toolbar)
  
      initPagerAdapter()
  
      tabs?.setTabTextColors(
          getDisabledTextColorFor(primaryColor),
          if (boolean(R.bool.accent_in_tabs)) accentColor
          else getPrimaryTextColorFor(primaryColor))
      tabs?.setSelectedTabIndicatorColor(
          if (boolean(R.bool.accent_in_tabs)) accentColor
          else getPrimaryTextColorFor(primaryColor))
      if (boolean(R.bool.show_icons_in_tabs)) {
          tabs?.setTabsIconsColors(
              getInactiveIconsColorFor(primaryColor),
              if (boolean(R.bool.accent_in_tabs)) accentColor
              else getActiveIconsColorFor(primaryColor))
      }
  
      buildTabs()
  
      tabs?.addOnTabSelectedListener(
          object : TabLayout.ViewPagerOnTabSelectedListener(pager) {
              override fun onTabSelected(tab: TabLayout.Tab?) {
                  tab?.let { postDelayed(50) { navigateToSection(it.position) } }
              }
  
              override fun onTabReselected(tab: TabLayout.Tab?) = scrollToTop()
              override fun onTabUnselected(tab: TabLayout.Tab?) {}
          })
      pager?.addOnPageChangeListener(
          TabLayout.TabLayoutOnPageChangeListener(tabs))
  
      pager?.offscreenPageLimit = tabs?.tabCount ?: 2
  
      navigateToSection(lastSection, true)
  
      favsViewModel.observe(this) { notifyFavsToFrags(it) }
      doAsync { favsViewModel.loadData(favsDB.favoritesDao(), true) }
  
  }
  </code></pre>