On(before)close eventlistener in Mobile App

On(before)close eventlistener in Mobile App

  

Hi OutSystems friends,

To determine how much time an OutSystems Mobile App was closed, before opened again (sleep / to background / appswitch), I would like to have some sort of OnBeforeClose action in my app to set a timestamp. So I can calculate the time an OutSystems App was "sleeping".

Is there an eventlistener / cordova plugin for this?

Or maybe one of you guys had a different approach/solution to a simular problem?

Regards,
Jasper

Solution

Hi Jasper,

You can use the pause event.

For example, in the OnReady of the BottomBar insert there a Javascript statement with this:

document.addEventListener("pause", onPause, false);

function onPause() {
    $actions.<yourclientaction>();
}

This will run the <yourclientaction> when you exit from your application. In that <yourclientaction> you can insert in local storage a timestamp to know when it went to sleep. Then in the OnApplicationResume client action get that value to compute the amount of time the application was sleeping.

Cheers,

José

Solution

Thanks José,

I tried exactly the same this afternoon (placed in Layout block) and it wouldn't work at all.
After repeating your steps it actually did work!

Regards,
Jasper