Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Admob interstitial ad opens again after close — Gideros Forum

Admob interstitial ad opens again after close

Hi all I've decided to resurrect an old game I started working on 9 years ago! I'm almost done and am just in the process of adding admob ads.

I have a simple function that I call which is:

function MyAds:displayInterstitial()
self.ADMOB:loadAd("interstitial", self.Interstitial)
end

I've made sure I am only calling this once in the scene but whenever I close the ad another one loads straight after it. I'm on the latest version of Gideros and the is on android api 30. I'm also enableTesting() not sure if that make a difference?

I wanted to see if anyone had any ideas before I go trying to do something hacky to hide them.

Comments

  • MoKaLuxMoKaLux Member
    edited April 2021
    I think I had the same issue with rewarded video ads, finally I had to do something like this:
    	-- ads rewarded video
    	self.videoadbtnclicked = false
    	local device = application:getDeviceInfo() -- Windows, Android, ...
    	self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google rewarded video id test
    	self.ADMOB_UNIT_ID = "ca-app-pub-3940256099942544/5224354917" -- google rewarded video test
    	-- admob (setup for rewarded video points)
    	if device == "Android" then
    		require 'ads' -- create real object for on device
    		self.ADMOB = Ads.new('admob')
    		self.ADMOB:enableTesting(true)
    		self.ADMOB:setKey(self.ADMOB_APP_ID)
    		self.ADMOB:addEventListener(Event.AD_DISPLAYED, function (e) 
    			print("AD_DISPLAYED. AD_TYPE: "..e.type)
    			self.videoadbtnclicked = false
    		end)
    		self.ADMOB:addEventListener(Event.AD_ERROR, function (e) 
    			print("AD_ERROR. AD_TYPE: "..e.type.." Error: "..e.error)
    			self.videoadbtnclicked = false
    		end)
    		self.ADMOB:addEventListener(Event.AD_FAILED, function (e) 
    			print("AD_FAILED. AD_TYPE: "..e.type.." Error: "..e.error)
    			self.videoadbtnclicked = false
    		end)
    		self.ADMOB:addEventListener(Event.AD_RECEIVED, function (e) 
    			print("AD_RECEIVED. AD_TYPE: "..e.type)
    			if e.type=="rewarded" and self.videoadbtnclicked then -- IMPORTANT
    				print("Video loaded, showing it.")
    				self.ADMOB:showAd("rewarded", self.ADMOB_UNIT_ID)
    				self.videoadbtnclicked = false
    			end
    		end)
    		self.ADMOB:addEventListener(Event.AD_DISMISSED, function (e) 
    			print("AD_DISMISSED. AD_TYPE: "..e.type)
    			if(e.type=="rewarded")then
    				print("Video dismissed.")
    			end
    			self.videoadbtnclicked = false
    		end)
    		self.ADMOB:addEventListener(Event.AD_REWARDED, function (e) 
    			print("AD_REWARDED. AD_TYPE: "..e.type)
    			if(e.type=="rewarded")then
    				print("Video rewarded, yay!")
    			end
    			self.videoadbtnclicked = false
    		end)
    	else
    		self.ADMOB = {} -- create fake object for testing in windows player
    		self.ADMOB.loadAd = function() end
    		self.ADMOB.showAd = function() end
    		self.ADMOB.hideAd = function() end
    	end
    The key here was to add self.videoadbtnclicked and check its value in Event.AD_RECEIVED.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Accepted Answer
    @anefiox, where do you call showAd() ?
    loadAd() only preloads an Ad, showAd() shows an ad (eventually loading it if not yet preloaded). You shouldn't call showAd() in the AD_RECEIVED handler as @MoKaLux did, because if you do you don't know when the ad will be actually shown (it will depend on the time taken to load the ad from the network).

    The way it is supposed to work is as follow:
    1. Call loadAd() as soon as possible in your code to have an Ad ready to be shown when needed.
    2. When you need to show an ad, check if the Ad has been loaded. If so call showAd(), otherwise handle the 'ad not ready' case as you wish (inform the user, skip the ad, try to call loadAd() once more, etc)
    3. As soon as the ad was shown (AD_DISMISSED) call loadAd() again to preload the next Ad.

    I was working on Gideros ads plugin yesterday, and I noticed some ad providers would automatically load next Ad when the previous was shown, thus trigering AD_RECEIVED even if you didn't call loadAd() yourself. I saw that it AppLovin code, which was copied from Admob code...

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks. That worked! I think the example provided in the documentation has to change.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • please provide the steps (code) so I can update the doc (wiki) :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.