QuoteBut 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
Hi Stefan, currently I can't recommend an "out of the box" solution.
The most promising path are the upcoming Cordova Plugin integration tools and all cordova plugins which offer "background" upload/download capabilities.
Namely this plugin https://github.com/spoonconsulting/cordova-plugin-background-upload
and this plugin https://github.com/sgrebnov/cordova-plugin-background-download/blob/master/src/ios/BackgroundDownload.m
are plugins dealing under IOS with the "NSURLSession" API https://developer.apple.com/documentation/foundation/nsurlsession?language=objc
which ensures upload/download "out of process" by the system networking daemon.
So regardless if your GMI process is in the foreground or background using this API ensures that uploads/downloads continue.
I can't estimate if on Android the same happens (need to ask my GMA colleague)
For the download plugin I already made a sample for GMI 1.30.06
(Are you in the 3.10 Genero-EAP ?) downloadable from https://www.generomobile.de/gmi/cdvdownload.zip
For the upload I need to check if the upload plugin is already usable in GMI.
If none of the plugins are fitting your purpose then there is also the possibility adding a custom frontcall in GMI/GMA using the appropriate system APIs . This could be done already for the released GM 1.20.
I can only warn to use
ON IDLE 1
to do networks syncs.
1. this will make you unhappy because this needs to be implanted in each possible DIALOG the user enters and will hence lead to code pollution.
2. If you are in INPUT statements you may run into focus and validation issues
(reminder: ON IDLE flushes the current field, if you are in an INTEGER field and type accidentally "a" then you get an unwanted validation error and your end users will be irritated)
3. It won't work anyway if your app is a longer time in the background (at least on IOS).
As mentioned my comments are pretty IOS centric, but I guess the Android answer will be similar
Regards, Leo