How to close/finish my Vungle rewrded video ad programatically, as if user closes the app or put in background?

305 Views Asked by At

I am implementing the Vungle ads in my android app,

the problem is when the user closes the app by swiping up the app after pressing the overview button (the right one from default buttons), meanwhile, Vungle rewarded ad was running,

After closing the application while the rewarded ad is running Vungle ad behavior is weird,

when the user open the app again it never shows the new ad, even ad is available (canPlayAd returns true) but ad could not be played, or sometimes rewarded call back runs, even app is closed by the user.

I just want to destroy/close the Vungle rewarded ad, when the application's main activity's onDestroy called. Thanks

        if (Vungle.canPlayAd(placementId)) {
        editActivityUtils.logGeneralEvent(context, "rewardedVdoPlayed", "$cat_name: $name")
        firebaseAnalytics.setUserProperty("rewardedVdoPlayed", "$cat_name")
        Vungle.playAd(placementId, adConfig, object : PlayAdCallback {
            override fun onAdStart(id: String) {}
            override fun onAdEnd(id: String, completed: Boolean, isCTAClicked: Boolean) {
                Log.e("app", "Vungle ad end")

                if ((!(context as TemplatesMainActivity).isDestroyed) && completed) {
                    Vungle.loadAd(placementId, object : LoadAdCallback {
                        override fun onAdLoad(id: String?) {
                        }

                        override fun onError(id: String?, exception: VungleException?) {
                        }
                    })
                    Log.e("app", "Vungle ad rewarded")
                    editActivityUtils.logGeneralEvent(context, "gotTemplateByRewardedVdo", "$cat_name: $name")
                    firebaseAnalytics.setUserProperty("gotTemplateByRewardedVdo", "$cat_name")
                    goToEditorWithoutAD(cat_name, name)
                }

            }

            override fun onAdEnd(id: String) {}
            override fun onAdClick(id: String) {}
            override fun onAdRewarded(id: String) {
                Log.e("app", "Vungle ad rewarded")


            }


            override fun onAdLeftApplication(id: String) {
                Log.e("app", "Vungle left app")


            }

            override fun onError(id: String, exception: VungleException) {
                Log.e("app", "Vungle ${exception.localizedMessage}")

            }
        })
    }
1

There are 1 best solutions below

1
On

Sorry, your questions do not include enough information for me to give you an answer. Please submit a ticket to Vungle [email protected] for help.

Below are some questions for the issue, please include the information and send to Vungle. The information should help Vungle to know what exactly happened on your side.

I am implementing the Vungle ads, the problem is when the user destroys the application while Vungle rewarded ad was running, after that Vungle ad behavior is weird,

it never shows the new ad, even ad is available,

-- In this case, yes, it looks weird. Have you checked the ad available before calling the play function?

or sometimes rewarded call back runs, even app is closed by the user.

-- Not sure which callback did you exactly mean. Please show the code if possible.

I just want to destroy Vungle rewarded ad, when activity's onDestroy called.

-- There should be nothing you need to do to destroy Vungle rewarded ads. Vungle should be able to help you figure out the weird behavior.

Please provide also provide information to Vungle if you have:

Platform(s)(iOS, Android, Windows):

Device and operating system version:

Vungle APP ID(s):

APP Name(s):

Application Status, i.e Testmode /Active / Inactive :

Vungle SDK Version(s):

Which type of Vungle SDK integration? (iOS, Android, Windows, or Plugin):

If using “Mediation” service, which one: