1091
Views
19
Comments
Solved
Force Mobile App to Close
Discussion

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


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP
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


2020-02-16 03-29-56
Karnan M

Thank you!!

2024-03-25 06-19-08
Harlin Setiadarma

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

Do I need to install Cordova plugin?

Thanks.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

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

2024-03-25 06-19-08
Harlin Setiadarma

Thanks Daniël.

It was a very useful info.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Your welcome Harlin, 

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

Regards,

Danfiel

2024-03-25 06-19-08
Harlin Setiadarma

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

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Ha my mistake.

2020-01-06 05-15-34
Rom_

Hi Daniel,

Couldn't make it to work on ipad.

Pls advise.

Regards,

Rom

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

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

2020-01-06 05-15-34
Rom_

Hi Daniel,

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

Regards,

Romuel

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Romuel,

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

Regards,

Daniel

2024-03-25 06-19-08
Harlin Setiadarma

Hi Romuel,

According to:

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

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

2020-01-06 05-15-34
Rom_

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.

2024-03-25 06-19-08
Harlin Setiadarma

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. 

2020-01-06 05-15-34
Rom_

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

2019-09-24 18-41-25
Jorge Martins
 
MVP

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)

ForceRedirect.oap
2020-01-06 05-15-34
Rom_

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

2020-01-06 05-15-34
Rom_

Hi Jorge,

The solution you suggested works! 

Thanks!

Romuel

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