Jalal Khan
Jalal Khan

Reputation: 1

MoPub advance Biding

Im integrating mopub in my Android app, I integrated mupub in my App as per the documentation and its working fine I`m receiving test Ads but there is an issue in the Interstitial Ad, my app crashes after showing the ad, other Ads(Banner and Native) are working but only Interstitial has the problem.

This is my code for the Interstitial Ad.

class SplashScreen : AppCompatActivity() {

private var check = true
private var check2 = true
private var mInterstitial: MoPubInterstitial? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val win = this.window
    win.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
    )
    setContentView(R.layout.activity_splash_screen)
    supportActionBar?.hide()

    val facebookConfig =  HashMap<String, String>();
    facebookConfig.apply {
        put("banner", "")
        put("interstitial", "true")
    }
     AudienceNetworkAds.initialize(this)
     val sdkConfiguration =  SdkConfiguration.Builder("b860fe901ec44849975526de44970b4a")
    sdkConfiguration.withMediatedNetworkConfiguration(FacebookAdapterConfiguration::class.java.name,
        facebookConfig);
    sdkConfiguration.withLogLevel(MoPubLog.LogLevel.INFO).withLegitimateInterestAllowed(false).build();

    val listner = object : MoPubInterstitial.InterstitialAdListener {
        override fun onInterstitialLoaded(p0: MoPubInterstitial?) {

            try{
                if (check2)
                    if (mInterstitial?.isReady == true) {
                        try {
                            mInterstitial?.show()
                        }
                        catch (e:Exception){
                            Log.e("Interstital",e.message.toString())
                        }
                    }

            }
            catch (e:Exception)
            {
                Log.e("Ad",e.message.toString())
            }
            check = false
        }

        override fun onInterstitialFailed(p0: MoPubInterstitial?, p1: MoPubErrorCode?) {

            Handler(Looper.getMainLooper()).postDelayed({

                if (check) {
                    val intent = Intent([email protected], MainActivity::class.java)
                    startActivity(intent)
                    check = false
                    finishAffinity()
                }
            }, 1000)
        }

        override fun onInterstitialShown(p0: MoPubInterstitial?) {
            TODO("Not yet implemented")
        }

        override fun onInterstitialClicked(p0: MoPubInterstitial?) {
            TODO("Not yet implemented")
        }

        override fun onInterstitialDismissed(p0: MoPubInterstitial?) {

            val intent = Intent([email protected], MainActivity::class.java)
            startActivity(intent)
            finishAffinity()
        }

    }

    MoPub.initializeSdk(this,sdkConfiguration.build()) {

    }


    mInterstitial = MoPubInterstitial(this, "b860fe901ec44849975526de44970b4a")
    mInterstitial?.interstitialAdListener = listner

/*

    val logo = findViewById<ImageView>(R.id.logo)
    logo.animate().scaleX(1f).duration = 500
    logo.animate().scaleY(1f).duration = 500

*/

    mInterstitial?.load()
}

override fun onPause() {
    super.onPause()
    MoPub.onPause(this);
}

override fun onStop() {
    super.onStop()
    MoPub.onStop(this);
}

override fun onResume() {
    super.onResume()
    MoPub.onResume(this);

    Handler(Looper.getMainLooper()).postDelayed({

        if (check) {
            val intent = Intent([email protected], MainActivity::class.java)
            startActivity(intent)
            finishAffinity()
            check2 = false
            check = false
        }
    }, 10000)

}

override fun onDestroy() {
    super.onDestroy()
    if (mInterstitial != null) {
        mInterstitial?.interstitialAdListener = null
        mInterstitial?.destroy();
        mInterstitial = null;
    }
}

}

This the error I`m getting

Upvotes: 0

Views: 19

Answers (0)

Related Questions