ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Process functions / Threads, semaphores, signals and mutex
  • Displaying the notification
  • Battery management and persistent notification
  • Use case specification (Android 14)
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Makes a thread persistent.
The application is not stopped as long as at least one persistent thread is running (even if all its windows have been closed).
Using a persistent thread allows you to:
  • continue playing music even if the window is closed.
  • transmit GPS coordinates on a permanent basis.
Example
// Start the thread that triggers the reading of a sound track
ThreadExecute("MyThread", threadGlobalContext, ProcPlayMusic)

// Creates the notification to display while playing the sound track
Notif is Notification
Notif.Title = "Playing..."
Notif.ActionClick = ProcStopMusic
// Prevent hiding the notification
Notif.Deletable = False

// Make the thread persistent to prevent the application from being closed 
// as long as the thread is not ended
// Specified use (Android 14: thpMediaPlayback (music playback)
ThreadPersistent("MyThread", Notif, thpMediaPlayback)
Syntax
<Result> = ThreadPersistent(<Thread name> , <Notification to display> [, <Usage>])
<Result>: Boolean
  • True if the thread is persistent,
  • False if an error occurs. To get more details on the error, use ErrorInfo with the errMessage constant.
<Thread name>: Character string
Name of the thread that must be persistent. This name is given when running the thread (ThreadExecute). This thread must exist and use the application global context.
<Notification to display>: Notification variable
Name of the Notification variable corresponding to the notification to be displayed while the persistent thread continues to execute.
This notification must not be already displayed. If a persistent thread is running when ThreadPersistent is called, the notification associated with this thread will be replaced with the specified notification. When the thread execution is ended, the notification will be automatically hidden if no other persistent thread is in progress.
<Usage>: Integer constant
New in version 2025
Constant used to define the use case of a persistent thread. This parameter is required from Android 14 onwards.
thpCameraAccess the camera from the background.
Permission added: android.permission.FOREGROUND_SERVICE_CAMERA (Manifest type: camera)
Additional permission required: android.permission.CAMERA
thpConnectedDeviceInteraction with connected devices. For example, interaction with a heart rate sensor.
Permission added: android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE (Manifest type: connectedDevice)
Additional permissions required:
  • at least one of the following permissions must have been declared:
    • android.permission.CHANGE_NETWORK_STATE, android.permission.CHANGE_WIFI_STATE,
    • android.permission.CHANGE_WIFI_MULTICAST_STATE, android.permission.NFC,
    • android.permission.TRANSMIT_IR,android.permission.UWB_RANGING
  • or at least one of the following permissions must have been declared and accepted:
    • android.permission.BLUETOOTH_ADVERTISE,
    • android.permission.BLUETOOTH_CONNECT,
    • android.permission.BLUETOOTH_SCAN
thpDataSyncSynchronizing data. E.g., importing data from a database.
Permission added: android.permission.FOREGROUND_SERVICE_DATA_SYNC (Manifest type: dataSync)
Additional permission required: None
thpHealthPhysical activity tracking.
Permission added: android.permission.FOREGROUND_SERVICE_HEALTH (Manifest type: health)
Additional permission required:
  • Permission to declare: android.permission.HIGH_SAMPLING_RATE_SENSORS
  • or at least one of the following permissions must have been declared and accepted: android.permission.BODY_SENSORS, android.permission.ACTIVITY_RECOGNITION
thpLocationActions requiring location access, such as navigation and location sharing.
Permission added: android.permission.FOREGROUND_SERVICE_LOCATION (Manifest type: location)
Additional permissions required: At least one of the following permissions must have been declared: android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION
thpMediaPlaybackContinuous audio or video playback from the background.
Permission added: android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK (Manifest type: mediaPlayback)
Additional permissions required: None
thpMicrophoneAudio recording from the background
Permission added: android.permission.FOREGROUND_SERVICE_MICROPHONE (Manifest type: microphone)
Additional permissions required: android.permission.RECORD_AUDIO
thpShortServiceCritical operation to be completed without interruption. This operation must not exceed three minutes.
Permission added: None (Manifest type: shortService)
thpSpecialUse
(Default value)
Operation whose use case does not correspond to any of the predefined cases.
Permission added: android.permission.FOREGROUND_SERVICE_SPECIAL_USE (Manifest type: specialUse)

Note: You can describe the use case of the persistent thread more precisely by adding the following node as a child of the <service> node in the application manifest:
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="use case explanation"/>
This may be necessary to publish your application on Google Play.
Remarks

Displaying the notification

  • A notification is always displayed during the execution of a persistent thread. In this way, users are informed that the application they have launched is still running, even if no more windows are open. They can take control of this application by clicking on the notification.
    The application can also be reactivated when the notification is clicked. Simply specify the ActivateApplication property in the Notification variable.
  • Tip: Do not open a window from a persistent thread. Windows can be opened from the procedure called by the notification.
  • Starting with Android 13, users can hide the notification. You can prevent this using the Deletable property of the Notification variable.

Battery management and persistent notification

Starting with Android 10, optimizing the use of the integrated battery can interrupt a thread made persistent with ThreadPersistent. In this case, SysBatteryOptimBackground allows the application to use the battery and also keeps the persistent thread.
New in version 2025

Use case specification (Android 14)

Starting with Android 14, it is necessary to indicate the use case(s) of the persistent thread when calling ThreadPersistent, using the <Usage> parameter.
A new permission will be automatically added according to the specified use cases.
Some use cases also require associated permissions to be declared. These permissions are not added automatically. If the associated permissions have not been added to the application, a fatal error will be raised.
For example, if the thpCamera constant is used, the "android.permission.FOREGROUND_SERVICE_CAMERA" permission will be automatically added to the application, and the "android.permission.CAMERA" permission will be required.
Related Examples:
Android Persistent Notifications Android (WINDEV Mobile): Android Persistent Notifications
[ + ] This example is used to create persistent notifications that appear even if the application is not used anymore.
A persistent thread run when the starting device is used to send the notifications.
Business / UI classification: Neutral code
Component: wd300android.jar
Minimum version required
  • Version 18
Comments
Click [Add] to post a comment

Last update: 02/14/2025

Send a report | Local help