PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

This page concerns the 23 + version of WINDEV Mobile. Upgrade your version.
  • Operating mode
  • Handling background tasks
  • Specific features for Android
  • Specific features for iOS
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Adds a new background task. This task will be run periodically when the application is stopped or when the application is in background.
Example
// Asks to process the incoming emails once a day
BackgroundTaskAdd(ProcBackgroundEmailProcess, 24*60)
PROCEDURE ProcBackgroundEmailProcess()
// Process the pending emails
n is int = ProcessIncomingEmails()
IF n > 0 THEN
// Notifies the user
notif is Notification
notif..Title = "Process completed"
notif..Message = StringBuild("%1 emails have been processed", n)
NotifAdd(notif)
END
Syntax
<Result> = BackgroundTaskAdd(<Procedure Name> [, <Time Interval>])
<Result>: Integer
  • Identifier of added task,
  • 0 if an error occurred. To find out the error details, use ErrorInfo.
<Procedure Name>: Character string (with or without quotes)
WLangage procedure ("callback" procedure) called when running the task.
This procedure must be a global procedure of project and it must expect no parameter. Otherwise, a fatal error will occur during the call to BackgroundTaskAdd.
<Time Interval>: Optional integer
Minimum time interval (expressed in minutes) between two task executions. Used to guarantee that the task will not be run during this time interval. However, the system can increase the time interval according to several factors (important workload, low battery, ...). Therefore, the real time interval can change and it can be quite long (several hours).
By default:
  • the time interval between two task executions is set to 1 hour.
  • the minimum time interval allowed is set to 15 minutes.
This parameter can correspond to:
  • an integer corresponding to the number of minutes,
  • a Duration variable,
  • Versions 23 and later
    the indication of duration in clear ('20min' for example).
    New in version 23
    the indication of duration in clear ('20min' for example).
    the indication of duration in clear ('20min' for example).
Remarks

Operating mode

Once added, the background task is automatically run by the system at regular time interval.
The task is persistent, it will continue to be run periodically when the application is stopped, even when the device is restarted.
If the task is triggered while the application is not started, the application will be run in background (without opening the first project window), the initialization process of project and the declaration process of classes and sets of procedures will be run before calling the procedure associated with the task.
The task will be run when the application is not started or when the application is in background. If the application is displayed in the foreground, its execution will be postponed.
As the task can be run in a secondary application thread, the code of WLanguage procedure must contain no access to the application GUI and no opening of dialog boxes (via Info, Error, etc.). If the task must interact with the users, you have the ability to use the notifications (Notifxxx functions).

Handling background tasks

  • From the editor, you can specify that a procedure must be run in background task by enabling the corresponding option from the setting window of procedure automation. The task will be automatically added during the next application start: in this case, there is no need to call BackgroundTaskAdd.
Android

Specific features for Android

  • Debugging:
    To simplify the debugging, you can force the execution of a background task via ADB by using the following command line:
    adb shell cmd jobscheduler run -f <application> <id>

    where:
    • <application> corresponds to the package name of application as defined in the generation wizard (ex: com.mycompany.myapplication).
    • <id> is the identifier of task to run (returned by BackgroundTaskAdd).
  • Required version: Adding background tasks is available for the devices running Android version 5.0 or later (api level 21).
    A fatal error occurs if the function is used with an earlier system version.
    To find out the version of Android system on which the application is run, use SysAndroidVersion.
  • Required permissions:
    The call to this function modifies the permissions required by the application.
    Required permissions:
    RECEIVE_BOOT_COMPLETED: allows an application to receive the ACTION_BOOT_COMPLETED that is diffused after the system finishes booting.
  • Once run, the task in background continues to operate as long as the application is installed.
  • The tasks in background are not called in the simulator.
iPhone/iPad

Specific features for iOS

  • Runtime duration:
    The background tasks have a total of 30 seconds to be run. If this time-out is exceeded, the application is directly stopped (this time-out can be reduced according to the system availability). Therefore, the task execution must be as fast as possible.
    Practically, the system is using the execution time of task to define the real frequency at which it must be called.
  • Debugging:
    You have the ability to debug the background tasks via Xcode, by triggering them manually via "Debug .. Simulate Background Fetch".
  • In order for the system to consider that the application can run background tasks, the application must perform network requests (calls to Webservices, HTTP requests, access to a HFSQL database, GPS, Email, ...). Indeed, iOS checks whether the application exploits data coming from the network.
  • The application must be able to run background tasks. On the device, in the "Device parameters .. Application name", the option "Refresh in background" must be checked.
  • When the application is specifically closed by a double press on the Home button and a swipe, the background procedure has less chances to be run.
  • The procedure will not be called anymore if the devices switches to "energy saving" mode.
  • The time-out between two procedure executions will be reduced if the device is plugged and connected to a WiFi network.
  • The frequency at which the application is enabled by the user will impact the call frequency of procedure.
  • The faster the request execution is, the shorter the time between two executions. In most cases, a long execution time of procedure means that the calls will be spaced out in time. The system gives priority to the procedures that consume less CPU.
Components
Android wd230android.jar
Minimum required version
  • Version 23
Comments
Click [Add] to post a comment