1. Home
  2. Docs
  3. Monetize App SDK Document...
  4. Use Manual
  5. Ad Formats
  6. Interstitial

Interstitial

Prerequisites

Load & Show the Ad

Consider a scenario where a button click triggers an Interstitial and, subsequently, the NewActivity is launched from MainActivity.

Load

              # MainActivity.kt -> onCreate()
              val interstitialConfigId = ConfigBuilder.INTERSTITIAL_TEST_R89_CONFIG_ID
              val activityToShowOver = this
              var interstitialId = RefineryAdFactory.createInterstitial(
                  interstitialConfigId,
                  activityToShowOver,
                  afterInterstitial = {
                      // Here you could load the next activity or fragment. Basically recover app flow
                      Log.d("Interstitial", "After Interstitial")
                      // Example
                      val newActivityIntent = Intent(activityToShowOver, NewActivity::class.java)
                      activityToShowOver.startActivity(newActivityIntent)
                  }
              )

Show On Button Press

Some events take place in you app, such as a button press, tab change or opening a link.

If the Interstitial hasn’t Loaded yet or failed to load when you call show, the flow will continue normally


      # MainActivity.kt -> onCreate()
      // Example of a button press
      findViewById<Button>(<YOUR_BUTTON_ID>).setOnClickListener {
          RefineryAdFactory.show(interstitialId)
      }

Show on Creation of the Interstitial

This will increase the time it takes to perform the user action.

Because its making the Ad Request when the user takes the action. You should use the previous approach where we make the request and store the ad ID for instant showing it when the user performs the actions.

This is how we use Interstitial we use in Demos.


      # MainActivity.kt -> onCreate()
      findViewById<Button>(<YOUR_BUTTON_ID>).setOnClickListener {
          createInterstitial()
      }
        # MainActivity.kt
        private fun createInterstitial() {
            val interstitialAdId = ConfigBuilder.INTERSTITIAL_TEST_R89_CONFIG_ID
            val lifecycleEvents = object : InterstitialEventListener {
                /*
                 * We need to call show on the onLoaded event and on the OnFailedToLoad event,
                 * this is to show the ad in both cases so the afterInterstitial event is called
                 */
                override fun onLoaded() {
                    RefineryAdFactory.show(interstitialId)
                }
        
                override fun onFailedToLoad(error: R89LoadError) {
                    RefineryAdFactory.show(interstitialId)
                }
        
                // Implement other lifecycle event callbacks as needed
                override fun onOpened() {
                    // Handle ad opened event
                }
        
                override fun onClosed() {
                    // Handle ad closed event
                }
        
                override fun onClicked() {
                    // Handle ad clicked event
                }
        
                override fun onImpression() {
                    // Handle ad impression event
                }
            }
        
            interstitialId = RefineryAdFactory.createInterstitial(
                interstitialAdId, this,
                afterInterstitial = {
                    Log.d("Interstitial", "After Interstitial")
                },
                lifecycleCallbacks = lifecycleEvents
            )
        }

Lifecycle Events

You can subscribe to these events with the same method but passing a new object as a parameter. Details about this object can be found in the Reference.

OnClose is not present because we have an after interstitial event that is mandatory to pass as a parameter and holds the same functionality that OnClose with special cases.

After Interstitial

This is not passed as a separated object like the other Events because is mandatory to handle what happens after an Interstitial is closed. This is invoked in the SDK when:

  • Everything went right and the user just closed the full screen ad.

  • The ad hasn’t loaded yet and you tried to show it.

  • The ad has been Invalidated and you tried to show it. Gets invalidated when:

    • Fails to load.

    • Already shown.

    • Too Long without showing it.

  • The ad failed to show.

How can we help?