Skip to content

Background Tasks

Benjamin Eder edited this page Jan 20, 2019 · 2 revisions

Background tasks are tasks executing every few minutes (30 minute for example).

To define a new background task just add you own implementation of the BackgroundTask interface in lib/util/scheduler/task/.

Fill the execute method with what you want to do and add an const constructor.

Finally add the newly created class in the Tasks class in tasks.dart in the same folder.

Test background tasks

It is not easy to debug background tasks. To check the functionality of your task just use the action defined in the settings test bench and set break points in your IDE in the background task. You will only see the test bench when you are running the app in debug mode.

Run Background Tasks button in the test bench

If you need to check whether the tasks are really executed when the app is closed (for Android since iOS does not support headless tasks) you can execute the following via adb: adb shell cmd jobscheduler run -f edu.hm.cs.fs.guide7 999. You can then check the apps logs by calling adb logcat *:S flutter:V, BackgroundTest:V. Notice that you can only debug via setting a print statement in the background task code starting with [BackgroundTest].

Example:

print("[BackgroundTest] Yay the task works!");

Clone this wiki locally