Hi
I am not able to remove a runtime event that listens to notifications. I added the runtime event in the scene:show and remove it in the scene:hide. But anyway, when I change of scene the listener is still there. In order to check if the listener is still there I added a native show alarm that displays when I get a notification.
function scene:show( event ) local sceneGroup = self.view local phase = event.phase local options = event.params if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). audio.setVolume(0.8, { channel=2 }) elseif ( phase == "did" ) then composer.removeHidden( ) composer.removeScene(composer.getSceneName( "previous"),false) -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. audio.play( backgroundGameMusic, { channel=2, loops=-1, fadein=1000 }) settings.load() local function notificationListener(event ) if (event.type == "remote" ) then local information = event.custom decodedgame = json.decode(information) if (decodedgame.docId == options.docId) then native.showAlert( "DocID", decodedgame.docId.." = "..options.docId, { "OK" }) end end end Runtime:addEventListener( "system", onSystemEvent ) Runtime:addEventListener( "notification", notificationListener ) end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then Runtime:removeEventListener( "notification", notificationListeneridle ) Runtime:removeEventListener( "notification", notificationListener) Runtime:removeEventListener( "system", onSystemEvent ) -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then Runtime:removeEventListener( "system", onSystemEvent ) Runtime:removeEventListener( "notification", notificationListener ) Runtime:removeEventListener( "notification", notificationListeneridle ) -- Called immediately after scene goes off screen. end end
I have read that this is the way to remove runtime listeners, declare the in the show/did and remove them in the hide. So I dont understand what is wrong with it