Page 2 of 3

Timer

Posted: Thu Mar 14, 2013 6:05 pm
by Jonathan Clark

{sorry if this should be in a seperate thread, but I figured it was relevant enough to this topic to be additional related material. I can repost in separate thread if desired}

Regarding timed functions:

I currently have an app setup to run a function every X seconds. I believe i have noticed that even after closing out of the app, the function is still running in the background because I keep seeing my database call count rising. This leads me to a couple questions.

  1. I am invoking the gps getlocation device service on load of a particular page and I have the watch option turned on. Does this service continue to run even if the user backs all the way out of the application? And what would be the best method to stop this service.

  2. I have entered some custom javascript functions to the app, I'm assuming once the app is loaded those functions are available even when the application is not focused?

  3. Whats the method for actually 'closing' the application as opposed to backing out of the app and it still running functions in the bg?


Timer

Posted: Thu Mar 14, 2013 7:33 pm
by Kateryna Grynko

Hi Jonathan,

  1. Geolocation service works until user leaves the page. Even if app is minimized (works in background mode) then Geolocation would work. You can't force stopping for now. This functionality is considered to be added in future.

  2. If JavaScript asset is created via menu "Create New" then this code plugs in header and is available for all pages (whether app is focused or no).

  3. Run the following JavaScript to close the app:
    codenavigator.app.exitApp();/code


Timer

Posted: Sun Mar 17, 2013 2:12 pm
by Jonathan Clark

Thanks Katya!

Based on that information can you tell me if this logic seems correct.

I'd like the geo-location service to run as long as the app is running (minimized or focused), but I also want the user to be able to set the gps polling rate and stop the gps service when desired without closing the app. This is how I think I would accomplish this...

  1. Add an input on the users settings page that allows them to specify a polling rate (value saved in local storage variable)

  2. Add a start/stop toggle button on the users settings page

  3. Initiate the geo-location service on every page load, with the "watch" option turned off, and by using the interval timer method discussed in this thread.

  4. Use the polling value set by the user as the the value for the timer interval

  5. Put the geo-location timer function inside a function that first checks to see if the start/stop toggle is currently set to start.

  6. Add an "exit" button the main menu to allow users to close app completely which should also stop any background geo-location service that is running?

    Am I thinking this through correctly? Thanks for the input!


Timer

Posted: Mon Mar 18, 2013 3:34 pm
by Maryna Brodina

Hello! It's a part of your app logic :) If you have any specific question we'll be glad to help.


Timer

Posted: Tue Mar 26, 2013 7:37 pm
by Jonathan Clark

Hey Katya,

You had said in the previous response that the geolocation service continues to run until the user leaves the page. What I'm experiencing is that the geolocation service runs until the app is completely shut down regardless of what page is navigated to. Does this sound correct?


Timer

Posted: Tue Mar 26, 2013 9:24 pm
by Kateryna Grynko

Geolocation service works until app is closed or you're navigated to page via "Navigate to page" action with parameter "Use full screen refresh" (in this case you're navigated with the whole JS and CSS files reloading).


Timer

Posted: Wed Mar 27, 2013 12:03 am
by Jonathan Clark

Ahhh I understand. So i need to disable the back button and force the use of soft buttons to navigate through pages if I want to force the geolocation service to turn off when leaving a specific page?


Timer

Posted: Wed Mar 27, 2013 7:02 am
by Maryna Brodina

Hi,
yes, you are right.


Timer

Posted: Thu May 07, 2015 7:30 pm
by Mihai Das

hi,
can you please detailed this timer solution.
step by step :) I'm new
thanks


Timer

Posted: Fri May 08, 2015 8:34 am
by Alena Prykhodko

Hi Mihai,

With this function you set time out. There restdatasource01 - service name that you execute on time out. 5000 - time in ms.
presetTimeout( "restdatasource01.execute({})" , 5000); /pre