> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling a title Presence change

> XSAPI examples for subscribing to XBOX Live title Presence changes and wiring up handlers when a user starts, stops, or suspends a specific title.

This topic provides example code for handling a title Presence change.

## Subscribing to a title Presence change

#### Flat C API

```cpp theme={null}
uint64_t xuid{ 123 };

HRESULT hr = XblPresenceSubscribeToTitlePresenceChange(
    xboxLiveContext,
    xuid,
    titleId,
    &state.titlePresenceChangeSubscription
);
```

## Unsubscribing from a title Presence change

#### Flat C API

```cpp theme={null}
HRESULT hr = XblPresenceUnsubscribeFromTitlePresenceChange(
    xboxLiveContext,
    state.titlePresenceChangeSubscription
);

state.titlePresenceChangeSubscription = nullptr;
```

## Adding a title Presence change handler

#### Flat C API

```cpp theme={null}
state.titlePresenceChangedHandlerToken =  XblPresenceAddTitlePresenceChangedHandler(
    xboxLiveContext,
    [](void* context, uint64_t xuid, uint32_t titleId, XblPresenceTitleState titleState)
    {
        UNREFERENCED_PARAMETER(context);
        LogToFile("Title presence change notification received:");
        LogToFile("Xuid = %u, titleId = %u, titleState = %u", xuid, titleId, titleState);
    },
    nullptr
);
```

For more information, see
[XblPresenceTitleState](/reference/live/xsapi-c/presence_c/enums/xblpresencetitlestate).

## Removing a title Presence change handler

#### Flat C API

```cpp theme={null}
HRESULT hr = XblPresenceRemoveTitlePresenceChangedHandler(
    xboxLiveContext,
    state.titlePresenceChangedHandlerToken
);

state.titlePresenceChangedHandlerToken = 0;
```


## Related topics

- [Rich Presence example code](/services/xbox-services/community/presence/how-to/live-presence-howto-nav.md)
- [How to](/services/xbox-services/community/presence/how-to/index.md)
- [Handling a device Presence change](/services/xbox-services/community/presence/how-to/live-handling-a-device-presence-change.md)
- [XblPresenceTitlePresenceChangedHandler](/reference/live/xsapi-c/presence_c/functions/xblpresencetitlepresencechangedhandler.md)
- [XblPresenceAddTitlePresenceChangedHandler](/reference/live/xsapi-c/presence_c/functions/xblpresenceaddtitlepresencechangedhandler.md)
