Force Mobile App to Close

  

Hi,

I want mobile app to be closed if the user doesn't use it for some time(eg:20mits) and lets the app open as it is or forget to close.  Is there any way I can force to close the Mobile app? like session timeout in Web application.


Thanks,

Karnan


Solution

Hi Karam,

Yes I think it is possible.

Create On the Logics tab on Client Actions the server event OnApplicationReady:

  1. Goto Logic tab
  2. Right click "Client Actions"
  3. Select Add System Events --> On Application Ready
  4. Add a JavaScript flow element between the Start and End

In the javascript flow element enter the following code:

5000 is a timeout of 5 seconds, adjust it according to your needs.

Good Luck,

Daniel


Solution

Thank you!!

Hi, is the navigator.app.exitApp() a built-in?

Do I need to install Cordova plugin?

Thanks.

It is part of Cordova framework that is used by OutSystems to create IOS and android apps, no need to install a plugin.

Thanks Daniël.

It was a very useful info.

Your welcome Harlin, 

if my answer was  a solution to your question could you mark it as a solution?

Regards,

Danfiel

Unfortunately I'm not the topic starter, so I cannot mark it as solution.

Ha my mistake.

Hi Daniel,

Couldn't make it to work on ipad.

Pls advise.

Regards,

Rom

Hi Romuel,

It does work on my android phone, unfortunately i don't have an ipad to test on it.

Does it work on other devices? Iphone, Android?

Regards,

Daniel

Hi Daniel,

It only works for Android. We tried it on ipad and iphone but it does not close the app.

Regards,

Romuel

Hi Romuel,

That's a bummer. I'll see if I can find a solution for IOS. 

Regards,

Daniel

Hi Romuel,

According to:

https://developer.apple.com/library/content/qa/qa1561/_index.html

There's no way to exit app programmatically in IOS.

Thanks, Harlin.


In that case, is there a way to redirect to another screen inside an OnApplicationReady/OnApplicationResume system event if closing the app is not an option for iOS devices.

Yes, there's an action you can use to detect if it's under IOS or Android.

In the WebPatterns you can use the action CurrentOS to identify the device OS. 

Hi Harlin,

Thanks for your reply. But I was hoping there is another way to redirect to another screen inside OnApplicationReady or OnApplicationResume. This way, I won't have to close the app and just redirect to another screen instead.

Regards,

Rom

Hi Romuel,

What exactly is your use-case? Where would you want to redirect when the App first launches?

If it's a matter of forcing login on reopen, then you just need to setup session authentication. If not, consider this approach (I haven't thoroughly tested it, just quickly whipped something up):

  • Create Local Entity to store wether you need to redirect to some screen or not
  • Set local entity value on the OnApplicationReady and OnApplicationResume to force redirect
  • Define Block that, on its OnInitialize, reads local entity value and decides wether it should go to some Destination screen or just End.
  • Add Block to Layout (and LayoutBlank) blocks, so it's on every screen of your App
  • Make sure after redirecting you clear the local entity value so you don't keep redirecting.

(find a sample app attached)

Thanks, Jorge for this! Haven't thought of using a web block.  Will try this out later.

My use case is to redirect the user to a screen (most probably the login page) if he decides to cancel the Fingerprint authentication. On android I am able to exit the app so when user tries to resume the app, the fingerprint authentication kicks in again. In iOS, closing the app is not acceptable although still possible so I was thinking of redirection strategy. Perhaps you could suggest another solution.


Regards,

Rom

Hi Jorge,

The solution you suggested works! 

Thanks!

Romuel