Проблема с Interstitial Ads

После открытия приложение включается SplashScreen, где включается Interstitial Ads, по закрытию которого происходит переход на MainActivity, все работает но как-то не правильно после закрытия ads экран становится белым на 1-2с и только потом начинает загружать MainActivity

SplashActivity

class SplashActivity : AppCompatActivity(), AdMobFullscreenManager.AdMobFullscreenDelegate {
    internal var fullscreenManager: AdMobFullscreenManager? = null

    private val adManager: AdMobFullscreenManager?
        get() {
            if (fullscreenManager == null) {
               configureManager()
            }
            return fullscreenManager
        }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.splash_screen)

        if (isOnline()) {
            if (!SubscriptionProvider.hasSubscription()) {
                adManager!!.completed()
            } else {
                Handler().postDelayed({
                    startActivity(Intent(this@SplashActivity, MainActivity::class.java))
                }, 3000)
            }
        } else {
            Handler().postDelayed({
                startActivity(Intent(this@SplashActivity, MainActivity::class.java))
            }, 3000)
        }

    }

    private fun configureManager() {
   
            if (fullscreenManager == null) {
                fullscreenManager = AdMobFullscreenManager(this, this)
            } else {
                fullscreenManager!!.reloadAd()
            }
        
    }

    override fun ADLoaded() {
            if (adManager!!.tryingShowDone) {
                adManager!!.showAdd()
            } else {
                startActivity(Intent(this@SplashActivity, MainActivity::class.java))
            }
        
    }

    override fun ADIsClosed() {
            if (adManager!!.tryingShowDone) {
                val intent = Intent(this@SplashActivity, MainActivity::class.java)
                startActivity(intent)
            }
    }

    fun isOnline(): Boolean {
        val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val netInfo = cm.activeNetworkInfo
        return netInfo != null && netInfo.isConnectedOrConnecting
    }

}

AdMobFullscreenManager

class AdMobFullscreenManager(private val context: Context?, delegate: AdMobFullscreenDelegate?) {

    private var countRequestAd: Int = 0

    private var delegate: AdMobFullscreenDelegate? = null
    var tryingShowDone = false
    private var adMobState = AdMobState.Loading
    private lateinit var mInterstitialAd: InterstitialAd

    enum class AdMobState {
        Loaded,
        Loading,
        NoAd
    }

    init {
        if (!SubscriptionProvider.hasSubscription()) {
            mInterstitialAd = InterstitialAd(context)
            configure(delegate)
        }
    }

    private fun configure(delegate: AdMobFullscreenDelegate?) {
        mInterstitialAd.setAdUnitId(context?.getString(R.string.interstitial)!!)
        mInterstitialAd.loadAd(AdRequest.Builder().build())
        this.delegate = delegate
        mInterstitialAd.setAdListener(object : AdListener() {
            override fun onAdLoaded() {
                countRequestAd = 0
                adMobState = AdMobState.Loaded
                if ([email protected] != null) {
                    [email protected]!!.ADLoaded()
                }
            }

            override fun onAdFailedToLoad(errorCode: Int) {
                if (!SubscriptionProvider.hasSubscription()) {
                    [email protected]()
                }
            }

            override fun onAdClosed() {
                if ([email protected] != null) {
                    [email protected]!!.ADIsClosed()
                }
            }
        })
    }

    fun showAdd(): Boolean {
        var b = false
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show()
            b = true
        }
        return b
    }

    fun completed() {
        tryingShowDone = true
        if (adMobState == AdMobState.Loaded) {
            if (delegate != null) {
                if (!SubscriptionProvider.hasSubscription()) {
                    delegate!!.ADLoaded()
                }

            }
        } else if (adMobState == AdMobState.NoAd) {
            if (delegate != null) {
                delegate!!.ADIsClosed()
            }
        }
    }

    fun reloadAd() {
        countRequestAd++
        if (countRequestAd == MAX_REQUEST_AD) {
            adMobState = AdMobState.NoAd
            if (delegate != null) {
                delegate!!.ADIsClosed()
            }
            return
        }

        if (mInterstitialAd.isLoaded()) {
            adMobState = AdMobState.Loaded
            mInterstitialAd.show()
        } else if (!mInterstitialAd.isLoading()) {
            adMobState = AdMobState.Loading
            if (!SubscriptionProvider.hasSubscription()) {
                mInterstitialAd.loadAd(AdRequest.Builder().build())
            }
        }
    }

    interface AdMobFullscreenDelegate {
        fun ADLoaded()
        fun ADIsClosed()
    }

    companion object {
        private val MAX_REQUEST_AD = 3
    }

}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:screenOrientation="portrait"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar"
        android:usesCleartextTraffic="true">

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="" /> 

        <activity
            android:name=".SplashActivity"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
        </activity>
        
        
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:theme="@style/TranslucentTheme"
            tools:replace="android:theme" />
    
    </application>

</manifest>

App

class App : Application() {
   
    override fun onCreate() {
        super.onCreate()
        sInstance = this

        MobileAds.initialize(this)
    }

    companion object {

        private lateinit var sInstance: App 

        fun getInstance(): App {
            return sInstance
        }

        fun getInstance(activity: Activity): App {
            return activity.application as App 
        }
    }

}
implementation 'com.google.android.gms:play-services-ads:19.5.0'

Даже если делаю в разы проще например так не чего не меняется, проблема остается та же

SplashActivity

class SplashActivity : AppCompatActivity() {
    private lateinit var mInterstitialAd: InterstitialAd

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.splash_screen)

        mInterstitialAd = InterstitialAd(this)

        mInterstitialAd.setAdUnitId(this.getString(R.string.interstitial))
        mInterstitialAd.loadAd(AdRequest.Builder().build())
        mInterstitialAd.setAdListener(object : AdListener() {
            override fun onAdLoaded() {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show()
                }

            }

            override fun onAdClosed() {
                val intent = Intent(this@SplashActivity, MainActivity::class.java)
                startActivity(intent)
            }
        })

    }

}

При этом в приложении есть и другие Interstitial Ads которые работают хорошо и правильно. Подскажите пожалуйста в чем может быть дело и как это исправить?


Ответы (0 шт):