# ApplicationWillDeactivateDelegate ApplicationHasReactivatedDelegate

**URL:** <https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651>\
**Category:** Mobile\
**Tags:** unreal-engine, Android, question, CPP\
**Created:** [May 13, 2023, 4:48pm UTC](https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651 "2023-05-13T16:48:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NikPik666](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NikPik666](https://forums.unrealengine.com/u/NikPik666)\
**Post date:** [May 13, 2023, 4:48pm UTC](https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651/1 "2023-05-13T16:48:46Z")

</div>

Hi,

FCoreDelegates::ApplicationWillDeactivateDelegate  
FCoreDelegates::ApplicationHasReactivatedDelegate

Is there a reason why these delegates are not called when the game window loses/gains focus on Android?

They only get called in pairs with  
FCoreDelegates::ApplicationWillEnterBackgroundDelegate  
FCoreDelegates::ApplicationHasEnteredForegroundDelegate

when the game activity gets stopped/started again.

See LaunchAndroid.cpp:  
ActivateApp\_EventThread()  
SuspendApp\_EventThread()

---

<div class="post-metadata">

**Author:** ![EliasWick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eliaswick/32/1175208_2.png) [@EliasWick](https://forums.unrealengine.com/u/EliasWick)\
**Post date:** [May 14, 2023, 8:26am UTC](https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651/2 "2023-05-14T08:26:18Z")

</div>

The Android platform does not provide a direct way to detect focus changes for an individual window. So it can’t call: `FCoreDelegates::ApplicationWillDeactivateDelegate` and `FCoreDelegates::ApplicationHasReactivatedDelegate`.

So you should use the `onPause` and `onResume` methods instead.

The `FCoreDelegates::ApplicationWillEnterBackgroundDelegate` and `FCoreDelegates::ApplicationHasEnteredForegroundDelegate` delegates are called by the engine in response to the `onPause` and `onResume` methods. These delegates are not directly related to the focus changes of the game window, but rather to changes in the overall state of the application.

_If you need to detect focus changes for the game window on Android, you may need to use a different approach, such as listening for touch or key events._

---

<div class="post-metadata">

**Author:** ![NikPik666](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NikPik666](https://forums.unrealengine.com/u/NikPik666)\
**Post date:** [May 16, 2023, 2:23pm UTC](https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651/3 "2023-05-16T14:23:44Z")

</div>

After more investigation, I found a way to inform the game about focus changes.  
In LaunchAndroid.cpp:

```auto
// callback that receives android_native_app_glue events
static void OnAppCommandCB(...)
{
    ...
    switch (cmd)
    {
    ...
    case APP_CMD_LOST_FOCUS:
        ...
        // broadcast the "focus lost" event
FAppEventManager::GetInstance()->EnqueueAppEvent(APP_EVENT_RUN_CALLBACK, FAppEventData([]()
        {
            FCoreDelegates::ApplicationWillDeactivateDelegate.Broadcast();
        }));
        break;
    case APP_CMD_GAINED_FOCUS:
        ...
        if (bHasWindow && bHasFocus && bIsResumed)
        {
            ...
            // broadcast the "focus gained" event
FAppEventManager::GetInstance()->EnqueueAppEvent(APP_EVENT_RUN_CALLBACK, FAppEventData([]()
            {
                FCoreDelegates::ApplicationHasReactivatedDelegate.Broadcast();
            }));
        }
        break;
    ...
    }
    ...
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [June 15, 2023, 2:24pm UTC](https://forums.unrealengine.com/t/applicationwilldeactivatedelegate-applicationhasreactivateddelegate/1164651/4 "2023-06-15T14:24:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
