unregister onResume event listener 
Question

Hi,

We have a mobile app and we have set an onResume event listener.

document.addEventListener("resume", function onResume() {
    // Handle the resume event
    $actions.LayoutOnPullToRefresh();
}, false);


Navigating from the screen gave errors on console suggesting using onDestroy event.

So I've put JS node with script "document.removeEventListener("resume", onResume, false);" onDestroy event but now I have Cant find variable: onResume error. 

What is a proper way to handle listeners in mobile app?

mvp_badge
MVP

Hi Mykola,

Try this:

create local variable type object on your screen called onResumeFunc and also one as output parameter on your javascript node:

function onResume() {
    // Handle the resume event
    $actions.LayoutOnPullToRefresh();
};

$parameters.onResumeFunc = onResume;

document.addEventListener("resume", onResume, false);

After the javascript node set the local screen variable with the output parameter of your javascript node.

The local screen variable you pass into the javascript node for the OnDestroy as input parameter.

document.removeEventListener("resume", $parameters.onResumeFunc, false);

Regards,

Daniel

mvp_badge
MVP

Hi Mykola,

Just wondering where you able to solve your problem?

Regards,

Daniel

This is an old post but I used this implementation as a way of getting around trying to remove custom events.  

My original implementation was going to get getEventListeners(), and iterate and remove the events that way within the OnDestroy method, but it seems that getEventListeners is not defined within OutSystems' javascript.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.