Android: prevent app restart with dark mode change

Hi there. On Android when a user toggles the system’s dark mode, apps are per default restarted. This is the recommended behaviour, but is quite ugly and unnecessary.

I added uiMode to android:configChanges in the AndroidManifest.xml

and then added the following to Desktop::NativeDarkModeChangeDetectorImpl within juce_Windowinding_android.cpp:

void onActivityConfigurationChanged (jobject /*activity*/) override
{
    const auto isEnabled = getDarkModeSetting();

    if (darkModeEnabled != isEnabled)
    {
        darkModeEnabled = isEnabled;
        Desktop::getInstance().darkModeChanged();
    }
}

Works perfectly and is much nicer than having the app restart whenever the user changes the dark mode.

Thanks, that’s added here:

1 Like

Excellent, thank you!