How to refresh the screen automatically in mobile application

How to refresh the screen automatically in mobile application

  

Hi Team,

I am new to Outsystems. I am developing a mobile application with a chat functionality embedded in it. I want to refresh the chat screen that i definied automatically for every x seconds. Can you please let me know how can i refresh a mobile screen automatically.


Thanks,

-Dileep

Hi Venkata,

What do you want to refresh? Do you display data, and you want to refresh the query? Or do you want to call a REST service every X seconds? Or what?

Anyway, the way to do it is via JavaScript: call setInterval with a function body calling a Screen Action. Don't forget to clearInterval() in the OnDestroy.

Kilian Hekhuis wrote:

Hi Venkata,

What do you want to refresh? Do you display data, and you want to refresh the query? Or do you want to call a REST service every X seconds? Or what?

Anyway, the way to do it is via JavaScript: call setInterval with a function body calling a Screen Action. Don't forget to clearInterval() in the OnDestroy.

Hi Kilian,

Thanks for response. As i mentioned i had embedded a chat functionality using In-App Chat mobile forge component and i want to make this realtime. Currently every time i send a message in my chat screen, i had to go back and come back to see the updated chat responses.

So i thought if there is a way to achieve this by refreshing this chat screen automatically without i clicking something.


I tried creating a button and set its display property to none and a click event to call back the screen. Now i want to get this click event triggered automatically.


Can you help me setting up this feature.


Hi Venkata,

I explained above: use a setInterval() in the OnReady, and a clearInterval() in the OnDestroy. Like in this topic (even though the poster didn't quite get it right yet).

Kilian Hekhuis wrote:

Hi Venkata,

I explained above: use a setInterval() in the OnReady, and a clearInterval() in the OnDestroy. Like in this topic (even though the poster didn't quite get it right yet).

As you mentioned, i created OnReady Event in which i called in a JS with setInterval() and redirect to the chat screen after every 10sec and a clearInterval() in OnDestroy event. 

I am getting error "Too many Redirects" as shown below

Hi Venkata,

You should redirect to the screen, because that will indeed cause the "too many redirects". Instead, you should just refresh the query getting the chats, or the REST service retrieving the chats, and update the list that feeds the chat component. In Mobile Apps, if you refresh/change data bound to a Widget, the Widget refreshes automatically (for Blocks you need the handle OnParametersChanged).

Solution

Hi Venkata RajamVenkata Rajam,

As Kilian Hekhuis said yo can refer the demo on https://www.outsystems.com/forums/discussion/21226/tip-how-to-programmably-auto-refresh-a-mobile-screen/ . But by following this way the screen will get refreshed after every x seconds even if you dont have updated any chats. the best way to do that use firebase notification (https://www.outsystems.com/forge/component/1406/firebase/) component so that you can notify screen when the chats updates and on notify using firebase receiver you can refresh the chats. to do that follow the link to configure firebase https://www.outsystems.com/forums/discussion/25871/how-to-configure-the-firebase-plugin/

Solution

Hi,

Use web sockets instead of refreshing every second. For a chat application are web sockets the best way to post and get data. In the Forge you can find components to implement web sockets in your app.

 Regards

Hi Furkan Çetin ,

I am also suggesting the same  thing by using firebase (Inside firebase the communication will be on web sockets).