TIP: How to programmably auto refresh a mobile screen

Sometimes you might want to auto refresh a mobile screen, update graph, update new QR code etc

Step 1) Create a screen "MyScreen"

Step 2) Create a client action "RefreshScreen" and add a Javascript block "RefreshTimer" with the following code 

setTimeout($actions.RefreshScreen,5000); /* example will refresh screen every 5 seconds */

Next, add any logic you want to refresh

Example

Step 3) In your screen "On Initalize" event property attach this to your client action "RefreshScreen"

That's it!

Thanks for the tip!

Hi Robert, can you please provide sample app for mobile for this functionality. I am new to outsystems and trying to get this worked.

Thanks in advance

MN

- wrote:

Sometimes you might want to auto refresh a mobile screen, update graph, update new QR code etc

Step 1) Create a screen "MyScreen"

Step 2) Create a client action "RefreshScreen" and add a Javascript block "RefreshTimer" with the following code 

setTimeout($actions.RefreshScreen,5000); /* example will refresh screen every 5 seconds */

Next, add any logic you want to refresh

Example

Step 3) In your screen "On Initalize" event property attach this to your client action "RefreshScreen"

That's it!

Hi


Thanks so much for the tip. This does indeed work. I have a question though. 

Why does setTimeout() work? Shouldn't the instruction be setInterval instead? Every time the setTimeout() action runs it generates a new timeoutId. Why does the action keep on running? Shouldn't setTimeout() only run once?

Thanks in advance for the attention


Regards,

   Carlos LSJ


Carlos López Santibáñez Jácome wrote:

- wrote:

Sometimes you might want to auto refresh a mobile screen, update graph, update new QR code etc

Step 1) Create a screen "MyScreen"

Step 2) Create a client action "RefreshScreen" and add a Javascript block "RefreshTimer" with the following code 

setTimeout($actions.RefreshScreen,5000); /* example will refresh screen every 5 seconds */

Next, add any logic you want to refresh

Example

Step 3) In your screen "On Initalize" event property attach this to your client action "RefreshScreen"

That's it!

Hi


Thanks so much for the tip. This does indeed work. I have a question though. 

Why does setTimeout() work? Shouldn't the instruction be setInterval instead? Every time the setTimeout() action runs it generates a new timeoutId. Why does the action keep on running? Shouldn't setTimeout() only run once?

Thanks in advance for the attention


Regards,

   Carlos LSJ


Its a recursive function. Refresh Timer is on client action "RefreshScreen", and the javascript is called itself setTimeout($actions.RefreshScreen,5000); /* example will refresh screen every 5 seconds */


This is a really helpfull funktion for me. I need to send live geocoordinates (every 10 seconds) from my user client mobile to an REST API with a POST command.  Thank you so much!

I tried this and it works great! Can you tell me if it continues to do this and presumably consume data while the app is not active / phone is locked? Can this behavior be adjusted?

thank you for this code, but I just want to know how to make it to work on lock screens as well.

Thanks for sharing this tip!

Thank you for this awesome work.

No need to do now custom auto refresh functionality.

Jared Slayton wrote:

I tried this and it works great! Can you tell me if it continues to do this and presumably consume data while the app is not active / phone is locked? Can this behavior be adjusted?


I don't think it run in the background unless you use one of the running in background plugin. By default, around 5 minutes (not too sure about the length, CMIIW) after goes to background, the app will go to sleep mode, and all process halted.

Abdul quadir Saifee wrote:

thank you for this code, but I just want to know how to make it to work on lock screens as well.

 Hi,

I think you must use one of the running in background plugin, without this, I don't think it can run on lock screen.


Thanks for the tip!