An AppTask is a user-facing task type in CAMS.

Configure AppTasks

Define app task metadata, measures, and triggers in your study protocol.

Run and Track Tasks

Use AppTaskController and UserTask state/events to drive runtime behavior.

UI and Notifications

Render task cards in your app and notify users when tasks are available.

Extend the Model

Add custom UserTask types and register a UserTaskFactory.

End-to-end flow

1

Define an AppTask in protocol

Configure an AppTask with task metadata plus one or more background measures.
2

Trigger and enqueue a UserTask

When triggered, CAMS creates a UserTask and puts it on the task queue in the AppTaskController.
3

Render and execute in app UI

The app listens to the task queue and renders the task list and task for the user in the app, providing callback methods for starting, completing, or canceling tasks.
4

Handle completion and notifications

Task state transitions and local notifications are handled through the runtime APIs.
This page uses the PulmonaryMonitor app as a running example.

Task List

Task List

Task Done

Task Done

Configuring and using app tasks

App tasks are defined in the study_protocol_manager.dart file. For example, the sensing app task at the bottom of the list is created by this configuration:
As shown above, an AppTask follows the Trigger-Task-Measure domain model in CAMS - a trigger activates the task, and the task defines which measures to collect. In comparison to an BackgroundTask, an AppTask can be configured with user-facing properties: The above code adds a NoUserTaskTrigger with an AppTask of type sensing and measures WEATHER and AIR_QUALITY. When triggered, the task is enqueued and can be shown in the app UI. When the user starts it (for example by pressing “PRESS HERE TO FINISH TASK”), a background task is started and collects the measures, and the app task is marked as done. For more setup details, see the PulmonaryMonitor.

App task execution

When an AppTask is triggered, it is executed by an AppTaskExecutor:
  1. Based on the AppTask configuration, a UserTask is created. This user task embeds a BackgroundTaskExecutor which, later (when the app task is started), is used to collect the measures.
  2. This user task is enqueued in the AppTaskController. The AppTaskController is a singleton and is core to the handling of AppTasks, including creating notifications.
  3. All triggered user tasks are available in the userTaskQueue for custom rendering in the app.
  4. The user task has set of call-back methods for marking the task started, done, canceled, expired, all of which are called by the app.
  5. When the user tak is started it uses a embedded BackgroundTaskExecutor to collect the measures. This background data collection is stopped when the task is marked as done or, if one-time measures, when then measures are collected.

The AppTaskController and user task queue

In the PulmonaryMonitor, access to enqueued tasks is handled in sensing_bloc.dart. Use the userTaskQueue property on AppTaskController to access the queue:
An app can also listen to events on the user task queue:

Using user task(s) in the UI of the app

Enqueued user tasks can be rendered in any app-specific UI. In the PulmonaryMonitor app, the task list shown above is implemented in task_list_page.dart. For example, to build the scrollable list view of cards, the following StreamBuilder is used:
To render the UI of each cards representing a user task, the following StreamBuilder is used:
When the user taps PRESS HERE TO FINISH TASK, the user task is started using the userTask.onStart() method. If the task has a widget, that widget is pushed to the UI. For a non-UI sensing task, it starts and runs for 10 seconds. A UserTask has callback methods that can be called by the app:

Notifications

An app task can be configured with notification. If enabled, a local notification is sent with the task title and description. task_notification This notification setup uses flutter_local_notifications and requires app-level configuration. See Install and Configure.

Types of app tasks

Currently, CAMS supports different types of AppTasks, all enumerated in the AppTask class:

Extending the app task model

CAMS is extensible, so you can add custom app tasks by creating new UserTask types and registering them. This is similar to extending measures and probes, as described in Extending CAMS. The AudioUserTask in the Pulmonary Monitor is an example of a custom app task. Its custom user task implementation is in audio_user_task.dart:
To create and enqueue the right user-task type, CAMS uses a UserTaskFactory. Hence, you need to define such a user task factory for your custom types. For example, the factory for AudioUserTask looks like this:
Remember to register the custom factory in AppTaskController:
This is typically done during the initialization of CAMS in the app. In PulmonaryMonitor, it happens when the Sensing class is created in sensing.dart.