But what is the best way to run this in Background on the mobile Device?
I would like to be proven wrong, but my understanding is that what you are after, running in the background on the mobile device can't be done. The reason being that the Genero Mobile application is effectively single threaded and so whilst the fglrun process is handing the GUI side of the app, you can't have another fglrun process running in the background doing the file transfer.
Note: how RUN is listed in the limitations.
http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_mobile_bdl_limitations.html So this means you can't have something like this to sync silently every 60 seconds...
ON TIMER 60
-- Every 60 seconds upload/download data if necessary
RUN "export FGLGUI=0; fglrun background_sync"
This is how I figure most news apps work. Periodically check to see if any new articles and if so download them in the background whilst you continue to read the current article.
With this limitation you are pushed down the path of having an explicit action to manage the sync e.g.
ON ACTION sync
CALL sync() -- upload/download data via web-service
... and the user having started the sync has to wait for the sync to finish.
I have wondered in the past if you could do something like this ...
ON IDLE 1 -- or ON TIMER 1
CALL tiny_sync() -- upload/download small amount of data via web-service
... where the API you are using is responsible for making sure each transmission is very small, small enough so that it does not interrupt the users UI experience (less than a second). So you would have to split files into small sizes, send each piece individually, and join them back together at the other end. How small depends on your network capability. I have not tried to implement this concept to see if it can practically be done.
Reuben