# Basic Background Task (Save on Suspend)

## Goal

When the app is being suspended, start background allowance, save quickly, then end the task.

## Actions used

* `TaskServicesStartTaskAndAllowInBackground`
* `TaskServicesCancelTask`

## Variables

* `taskId` (String) (optional)

## Flow

1. State: `OnApplicationPause(true)` (or your “app suspending” trigger)
   * Go to `StartBackgroundAllowance`.
2. State: `StartBackgroundAllowance`
   * Action: `TaskServicesStartTaskAndAllowInBackground`
   * Save `taskId` output (optional).
   * Events:
     * `startedEvent` → `DoSave`
     * `failureEvent` → `DoSave` (fallback: still try a minimal save)
3. State: `DoSave`
   * Do your save work (keep it short on iOS).
   * Then go to `EndBackgroundAllowance`.
4. State: `EndBackgroundAllowance`
   * Action: `TaskServicesCancelTask`
   * Input: `taskId` (or leave empty to use `TaskServicesUtils.LastTaskId`)

## Notes

* Assign `quotaWillExpireEvent` on `TaskServicesStartTaskAndAllowInBackground` and add it as a Global Transition if you need an emergency “save minimal” path (see Use Case 2).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://assetstore.essentialkit.voxelbusters.com/features/task-services/playmaker/use-cases/use-case-1-basic-background-task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
