17
Views
5
Comments
Navigate to screen on application resume
Application Type
Mobile

Hi guys,

I'm currently developing a mobile application and I have the requirement to prompt the user to insert a PIN once he/she brings the app from the background to the foreground, event that I can catch on the "OnApplicationResume". Another requirement is that after inserting the PIN, the user should be redirected to the same screen open before sending the app to the background.

My problems are:

  • I can't use the "destination" node within the OnApplicationResume action;
  • I tried to send the user to the PIN screen using Javascript, but somehow after the PIN screen, when I redirect the user to the "Previous Screen", the app closes. I believe that the history is getting messed up somehow.

Have any of you went through something like this? What your thoughts here?

Thanks for the help,

Ricardo Pedroso

Rank: #67

Hi Ricardo,


One possible solution is to have a listener on the application pause and save on a client variable or local storage the screen where the user was when pausing the application. In this way, you can redirect to the correct screen when the application resumes using that information stored in the client variable or local storage.


Although there is no system event for On Application Pause directly on Service Studio, you can quickly implement it using OutSystems as it is well explained step by step in this post.


Hope it helps.


Kind Regards,
João

Rank: #9427

Hi João,

Thank you for your reply.

I'm already cathcing the "pause" event and I'm storing the last screen and also the timestamp (I need it to ask for the PIN only if X minutes have passed since the app was sent to background).

My problem is, how should I send the user to the PIN screen in the OnApplicationResume action? The navigation node is not available. I tried to:

  1. In the OnApplicationResume I used Javascript to send the user to the PIN screen with:
    1. window.location.replace;
    2. window.location.assign;
    3. window.history.pushState + window.history.go
  2. After the user fills the correct PIN, I want to send him/her to the last screen, which I have stored;
  3. If that last screen somehow has a link to the "PreviousScreen", the app closes, as OS somehow does not know what was the "PreviousScreen".

It seems that the history is messed up due to the way I'm sending the user to the PIN screen in the first place.

Regards,

Ricardo

Rank: #67

Hi Ricardo,


Ok, so you were already doing this!

My best guess would be that it has indeed to do with the way you are launching the PIN screen.

Is there any reason why you did that way and not using the PIN code forge component? It has a good step by step documentation, it was created by OutSystems Labs, it has tons of downloads and it would be my starting point for this functionality? 


Regards,
João

Rank: #9427

I understand that using this component would speed up the development, but all the logic to create the PIN, validate, UI, etc. is all done. And even checking the documentation, they mention that in the event the PIN was filled correclty, they are sending the user to the HomeScreen, which I could be doing also.

The problem is I don't want to send the user always to the same screen, I want to open the last screen open before sending the app to the background. And this problem persists regardless if I'm using the Pin Code Forge Component or my custom approach. And I'm already sending the user to the last open screen, since I'm storing it on the app pause event.

However, if that last open screen has a link to the "Previous Screen", or if the user is using an Android and presses the button back, the app closes - does not know which is the previous screen.

Regards,

Ricardo

Rank: #9427

Hi João,

I found a working solution for my specific problem. So we can close the topic and provide help for future developers that might need, here is my solution:

  1. To give some background, I am running some logic in the OnApplicationResume, that under a specific scenario could end up with the need to redirect the user to a specific screen. Since the OnApplicationResume action does not allow me to use the out of the box Destination node, I was doing this redirect through Javascript (which was messing up the navigation history);
  2. The truth is that there are alternatives to catch the application resume event, instead of relying on the OnApplicationResume action that OutSystem provides out of the box (example: https://www.outsystems.com/forge/component-overview/3408/mobile-events);
  3. That said, I can place a web block that will catch the resume event wherever I want, in this case, in the layout itself. Since this web block is placed in the context of a screen, I can use the Destination node as I want, and thus, I don't need any Javascript to redirect the user.

I hope this might be helpeful in the future for the community.

Thank you for your time!

Best regards,

Ricardo Pedroso