How to call a REST API action continuously after a defined time Interval in Mobile


I am using firebase-realtime DB & to update the location continuously to firebase from Mobile app, I am using the REST-API approach.

I want to call this API after every 3 minutes. What would be the possible best approach?

Note: I am already using the setInterval  JS method

Any Help Much Appreciated.

Hi Assif,

In mobile app using setInterval javascript method is a perfect way to schedule a task to happen on a fixed interval.



Thanks Daniël Kuhlmann ,

Can you guide me on below:

1- If I start the setInterval  & close the application without destroying i.e clearingInterval.

    What will happen?

2- How can clear the setInterval from any Screen in Mobile at a define condition.

Hi assif_tiger,

Regarding your first question, if you close your application it will no longer be running, so whatever setInterval() you have set will also terminate.

As for the second question... if you want to clear the setInterval() you will have to use the clearInterval() function, passing it the output of the initial setInterval(). If in doubt on how to accomplish this, you can check the details for instance here.

Since in Mobile Apps you can execute JS logic on a Client Action, it's simply a matter of calling the clearInterval() after checking for the condition you are interested in.

Be careful, as if you navigate to other screens without cleaning up, you may end up in a situation where your setInterval() logic is still running but you lost access to its variable (and so cannot stop it you need to).

If this is not what you were asking, then please further explain your usage scenario.