Why isnt my admob listener called?

Here is part of my build.settings

android = {    usesPermissions =    {       "android.permission.INTERNET",       "android.permission.ACCESS\_NETWORK\_STATE",          }, }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },

Here is part of the scene in which I can succesfully show banner ads from admob but the adlistener isnt being called.

local function adMobListener( event ) sometext.text = "Ad height is "..ads.height() if ( event.isError ) then    print("error")          end end ads.init( "admob", "ca-app-pub-#", adMobListener )

–I call ads.show inside of scene:create( event )

ads.show( "banner", { x=0, y=0} )

Also ads.height() returns 0 when I tried to call it directly.

How can I solve these issues?

Im using build 2014.2393

Where is your listener function scoped? Also inside the :create() event? If so, you should move this up and outside, so Lua recognizes its scope.

Brent

Both the ads.init and the listener is before and outside of scene:create.

can you get a log from your device?

on Android, I get an exception on some devices, after which listener is never called again (bug 34895 submitted) looks like this:

W/Ads     (22297): Interrupted during GADSignals creation. W/Ads     (22297): java.lang.InterruptedException W/Ads     (22297):      at java.util.concurrent.locks.AbstractQueuedSynchronizer .doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:975) W/Ads     (22297):      at java.util.concurrent.locks.AbstractQueuedSynchronizer .acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1282) W/Ads     (22297):      at java.util.concurrent.CountDownLatch.await(CountDownLa tch.java:207) W/Ads     (22297):      at zn.a(SourceFile:147) W/Ads     (22297):      at zn.b(SourceFile:180) W/Ads     (22297):      at aeg.a(SourceFile:120) W/Ads     (22297):      at afv.run(SourceFile:14) W/Ads     (22297):      at afx.run(SourceFile:30) W/Ads     (22297):      at java.util.concurrent.ThreadPoolExecutor.runWorker(Thr eadPoolExecutor.java:1076) W/Ads     (22297):      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Th readPoolExecutor.java:569) W/Ads     (22297):      at java.lang.Thread.run(Thread.java:856) I/Ads     (22297): Starting ad request.

Can you post the relevant parts of  your code for this?  I’m concerned about when you say it’s out side of your scene:create function…  Actually while I ask for that, let me be quite clear on how you do this:

main.lua: 

local ads = require("ads")   local sometext = display.newText("", display.contentCenterX, 10, native.systemFontBold, 20)   local function adMobListener(event)      .... your event handler code      sometext.text = "Height: " .. tostring(ads.height()) end ads.init("admob", yourProviderID, adMobListener)

yourscene.lua

local composer = require ( "composer" ) local scene = composer.newScene() local ads = require( "ads" )   ...   function scene:show( event )       local sceneView = self.view         if event.phase == "did" then            ads.show("banner", { x=0, y=0 } )       end end   function scene:hide( event )       local sceneView = self.view         if event.phase == "will" then             ads.hide()   -- optional if you want to hide ads in between scenes       end end

Now you can get the height of the ad inside the admob listener, but it’s going to be difficult to display that as part of the scene’s display hirearchy.  Since you likely are not really wanting that in your scene’s view, you can create your text in main.lua and then just reference it that way.  The ads.height() should be set following the call to ads.show() in your scene so you can make UI adjustments there.

Rob

Where is your listener function scoped? Also inside the :create() event? If so, you should move this up and outside, so Lua recognizes its scope.

Brent

Both the ads.init and the listener is before and outside of scene:create.

can you get a log from your device?

on Android, I get an exception on some devices, after which listener is never called again (bug 34895 submitted) looks like this:

W/Ads     (22297): Interrupted during GADSignals creation. W/Ads     (22297): java.lang.InterruptedException W/Ads     (22297):      at java.util.concurrent.locks.AbstractQueuedSynchronizer .doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:975) W/Ads     (22297):      at java.util.concurrent.locks.AbstractQueuedSynchronizer .acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1282) W/Ads     (22297):      at java.util.concurrent.CountDownLatch.await(CountDownLa tch.java:207) W/Ads     (22297):      at zn.a(SourceFile:147) W/Ads     (22297):      at zn.b(SourceFile:180) W/Ads     (22297):      at aeg.a(SourceFile:120) W/Ads     (22297):      at afv.run(SourceFile:14) W/Ads     (22297):      at afx.run(SourceFile:30) W/Ads     (22297):      at java.util.concurrent.ThreadPoolExecutor.runWorker(Thr eadPoolExecutor.java:1076) W/Ads     (22297):      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Th readPoolExecutor.java:569) W/Ads     (22297):      at java.lang.Thread.run(Thread.java:856) I/Ads     (22297): Starting ad request.

Can you post the relevant parts of  your code for this?  I’m concerned about when you say it’s out side of your scene:create function…  Actually while I ask for that, let me be quite clear on how you do this:

main.lua: 

local ads = require("ads")   local sometext = display.newText("", display.contentCenterX, 10, native.systemFontBold, 20)   local function adMobListener(event)      .... your event handler code      sometext.text = "Height: " .. tostring(ads.height()) end ads.init("admob", yourProviderID, adMobListener)

yourscene.lua

local composer = require ( "composer" ) local scene = composer.newScene() local ads = require( "ads" )   ...   function scene:show( event )       local sceneView = self.view         if event.phase == "did" then            ads.show("banner", { x=0, y=0 } )       end end   function scene:hide( event )       local sceneView = self.view         if event.phase == "will" then             ads.hide()   -- optional if you want to hide ads in between scenes       end end

Now you can get the height of the ad inside the admob listener, but it’s going to be difficult to display that as part of the scene’s display hirearchy.  Since you likely are not really wanting that in your scene’s view, you can create your text in main.lua and then just reference it that way.  The ads.height() should be set following the call to ads.show() in your scene so you can make UI adjustments there.

Rob