Skip to content

Setting up CLAID to run in the background in mobile Apps

This is only relevant for CLAID on mobile devices. On Servers/PCs, CLAID will anyways run in the background indefinitely.

Mobile apps on devices like smartphones and smartwatches are significantly restricted from running continuously in the background without user interaction. As such, applications on mobile devices typically are paused after a few minutes to preserve battery life, unless explicitly setting up components to run in the background.

On mobile devices, CLAID features to automatically run all Modules in the background and requests certain exemptions from the operating system. This ensures CLAID Apps keep running as long as possible, start automatically once the device has booted, and restart an automatically when crashed. For continuous data collection, make sure to start CLAID in the background on your mobile device.

Persistance level

You can configure different levels of "persistance" in CLAID. Those levels specify what measures CLAID is allowed to take to circumvent operating system measures to keep running as long as possible. Higher persistance levels might require higher permissions. Check out the section on persistance levels below.

Running CLAID in the background

To start CLAID in the background, you simply have to change the startup command. Check out the instructions for your target platform below.

Starting CLAID in the background

Choose the instructions below depending on which platform you target. Mind the tabs.

Simply change the start command to startInBackground in your MainActivity or main Application, and choose a persistance level. If you are unsure on where to execute this function, check the previous tutorial.

// use ``startInBackground`` to start CLAID in the background
CLAID.startInBackground(this,   
        "assets://CLAIDConfig.json",    // Path to config
        "Smartphone",   // Hostname
        "user01",       // Specify the user identifier here!
        "some_device",  // Device name (can be anything)
        CLAIDSpecialPermissionsConfig.regularConfig(),
        CLAIDPersistanceConfig.maximumPersistance() // <--- Choose the persistance level. Check below.
);

Simply change the start command to startInBackground and choose a persistance level. If you are unsure on where to execute this function, check the previous tutorial.

// use ``startInBackground`` to start CLAID in the background
CLAID.startInBackground(
    configFilePath: "assets://flutter_assets/assets/claid_test.json",
    hostId: "Smartphone",   // Host name
    userId: "user01",    // Unique user id
    deviceId: "my_device",    // Device name
    specialPermissionsConfig: CLAIDSpecialPermissionsConfig.regularConfig(),
    persistanceConfig: CLAIDPersistanceConfig.maximumPersistance(), // <--- Choose the persistance level. Check below.
    claidPackages: []
).then((value) => setState(() {
    claidStarted = true;
}));

.. coming soon ..

Persistance levels

CLAID supports multiple perstance levels that you can choose when starting CLAID in the background. Choosing a higher persistance level increases the stability of the application, with the highest level making the App almost "unkillable" (even by the user). When choosing a higher level, however, the user might need to provide more permissions to the App, which CLAID will request from the user automatically.

The following persistance levels are available with CLAID:

Auto Start on Boot Auto Restart on Crash (after 15 Minutes) Exempt from Battery Optimizations (App will not be put to standby) Prevent termination and uninstallation by user

minimumPersistance
onBootAutoStart
maximumPersistance
maximumPersistance + Device Admin Rights