598
Views
3
Comments
Solved
On(before)close eventlistener in Mobile App
Question

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

2020-03-05 14-29-02
José Costa
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é

2017-07-06 09-31-00
Jasper Oudenaarden

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

2022-10-30 15-16-24
Pedro Brandao

Hello,

I’m revisiting this topic because I have the same requirement.

However, not all of my screens have a bottom bar.

I need to execute this JavaScript once across all flows and screens so that the action runs every time the app is closed or sent to the background.

How can i make a global listener?

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