# onConfigurationChanged

> A callback to detect the device configuration changes when the application is running.

## Definition

* **Type:** Event
* **Namespace:** [UnityEngine.Android](/engine/7000.0/script-reference/unityengine/android.md)
* **Assembly:** UnityEngine.AndroidJNIModule

```csharp
public static event Action<AndroidConfiguration> onConfigurationChanged
```

### Remarks

Unity invokes this callback for the configuration changes related to the following aspects.

* Orientation

* Keyboard visibility

* Dark theme

* Screen layout

* Screen size

Screen size refers to the Android `screenSize` configuration change, which reports the size of the screen space available to the application, in density-independent pixels (dp). For example, the size changes when the device rotates, when the user resizes the application window in multi-window mode, or when the user folds or unfolds a foldable device. To read the new size, use [AndroidConfiguration.screenWidthDp](/engine/7000.0/script-reference/unityengine/android/androidconfiguration/screenwidthdp.md) and [AndroidConfiguration.screenHeightDp](/engine/7000.0/script-reference/unityengine/android/androidconfiguration/screenheightdp.md).

This callback isn't related to the [Screen](/engine/7000.0/script-reference/unityengine/screen.md) class. Values such as [Screen.width](/engine/7000.0/script-reference/unityengine/screen/width.md), [Screen.height](/engine/7000.0/script-reference/unityengine/screen/height.md), and [Screen.currentResolution](/engine/7000.0/script-reference/unityengine/screen/currentresolution.md) describe the rendering surface and the display in pixels, and Unity doesn't invoke this callback in response to changes in those values. For example, calling [Screen.SetResolution](/engine/7000.0/script-reference/unityengine/screen/setresolution.md) changes [Screen.width](/engine/7000.0/script-reference/unityengine/screen/width.md) and [Screen.height](/engine/7000.0/script-reference/unityengine/screen/height.md), but doesn't trigger this callback, because the screen space available to the application stays the same.

For more information on the configuration changes, refer to the [Android developer documentation](https://developer.android.com/guide/topics/resources/runtime-changes).

### Examples

```csharp
using UnityEngine;
using UnityEngine.Android;

public class MyApplication : MonoBehaviour
{
    AndroidConfiguration m_PrevConfig;

    public void Start()
    {
        m_PrevConfig = new AndroidConfiguration(AndroidApplication.currentConfiguration);
        AndroidApplication.onConfigurationChanged += OnConfigurationChanged;
    }

    public void OnDisable()
    {
        AndroidApplication.onConfigurationChanged -= OnConfigurationChanged;
    }

    private void OnConfigurationChanged(AndroidConfiguration newConfig)
    {
        if (m_PrevConfig.orientation != newConfig.orientation ||
            m_PrevConfig.screenLayoutSize != newConfig.screenLayoutSize)
        {
            ApplyUIChanges(newConfig.orientation, newConfig.screenLayoutSize);
        }

        if (m_PrevConfig.uiModeNight != newConfig.uiModeNight)
        {
            ApplyUINightMode(newConfig.uiModeNight);
        }

        if (m_PrevConfig.screenHeightDp != newConfig.screenHeightDp ||
            m_PrevConfig.screenWidthDp != newConfig.screenWidthDp)
        {
            ApplyScreenSizeChanges();
        }

        m_PrevConfig.CopyFrom(newConfig);
    }

    private void ApplyUIChanges(AndroidOrientation orientation, AndroidScreenLayoutSize layoutSize)
    {

    }

    private void ApplyUINightMode(AndroidUIModeNight nightMode)
    {

    }

    private void ApplyScreenSizeChanges()
    {

    }
}
```
