dotnet / dotnet/maui

Changing locale does not trigger OnConfigurationChanged

Open
#29,778 4 comments 0 reactions 0 assignees View on GitHub
area-core-lifecycle has-workaround partner/syncfusion platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I have set the `ConfigChanges.Locale` value but when the language is changed at runtime in the settings application, the `OnCreate` handler of the `MainActivity` is called instead of the `OnConfigurationChanged` handler. When I read the [Android documentation](https://developer.android.com/guide/topics/resources/runtime-changes) about handling configuration changes, I expect the `OnConfigurationChanged` handler to be called.

Edit: in our production app, an exception is thrown stating that the "MauiContext is null". The work-around mentioned in [this issue](https://github.com/dotnet/maui/issues/25443) fixes this exception, so it could be related?

### Steps to Reproduce

1. Create a project.
2. Add `ConfigChanges.Locale` to the `ConfigurationChanges` property of the activity attribute.
3. Override the `OnCreate` and `OnConfigurationChanged` methods in `MainActivity`.
4. Set breakpoints in the overridden methods.
5. Run the project.
6. Change the language in the settings application of your phone.
7. Return to the application.
8. Observe which breakpoint hits.

### Link to public reproduction project repository

https://github.com/saterijst1/ChangeConfigLocaleRepo

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

No, this is something new, Not sure, did not test other versions

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

Android 33

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Start by running the public reproduction project and tracing the overridden MainActivity.OnCreate and OnConfigurationChanged handlers while changing the device language on Android 33. Compare the callbacks with the expected Android configuration-change behavior and check the reported MauiContext exception; done means the intended handler is reliably invoked without that exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.