Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Runtime "system" Event Listener Not Being Removed
Started by ddubya82 May 07 2018 03:58 PM

2 replies to this topic
runtime removeeventlistener system

Best Answer horacebury , 07 May 2018 - 09:20 PM

removeEventListener should returns a boolean or nil, so that is expected.

 

Are you instantiating 'P' only once? Your results would indicate that the 'P' which you think you're removing the listener from is not the 'P' which you actually are removing from.

 

Have you tried putting a print statement inside the listener function and, instead of removing the listener, simply print out something when the remove should happen? This might tell you how often the remove is being attempted and if the function is being called spuriously.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 36 posts
  • Corona SDK

Hi all,

 

I'm using the following method to fix a problem with my snapshot during an app resume:

P.onSystemEvent = function ( event )
  if(event.type=="applicationResume") then
    P.powerGlow:invalidate()
  end
end

I'm registering using the following call:

Runtime:addEventListener( "system", P.onSystemEvent )

And I'm removing with this call:

Runtime:removeEventListener( "system", P.onSystemEvent )

The event registers fine and my snapshot updates as it should when the app resumes.  Problem is onSystemEvent is still being fired even after I remove the event listener, obviously indicating a problem with my remove call. 

 

The remove call is returning nil, not true or false as Documentation says it should.

 

Check out the following debug:

local removeResult = Runtime:removeEventListener( "system", P.onSystemEvent )
print("P.onSystemEvent = " .. tostring(P.onSystemEvent))
print("removeResult = " .. tostring(removeResult))

Returns:

P.onSystemEvent = function: 10624940
removeResult = nil

Any ideas? 



[TOPIC: post.html]
#2

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 2,956 posts
  • Corona SDK

  Best Answer

removeEventListener should returns a boolean or nil, so that is expected.

 

Are you instantiating 'P' only once? Your results would indicate that the 'P' which you think you're removing the listener from is not the 'P' which you actually are removing from.

 

Have you tried putting a print statement inside the listener function and, instead of removing the listener, simply print out something when the remove should happen? This might tell you how often the remove is being attempted and if the function is being called spuriously.



[TOPIC: post.html]
#3

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 36 posts
  • Corona SDK

Thanks for the debug tip, @horace,

 

Turns out I was adding the system listener inside of a loop.  :huh:

 

Onward I go.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: runtime, removeeventlistener, system