user-interface-samples icon indicating copy to clipboard operation
user-interface-samples copied to clipboard

Per-app Language Preferences Sample screen flash and android:configChanges problem

Open winstonsung opened this issue 1 year ago • 1 comments

Steps to reproduce:

Without layoutDirection|locale|screenLayout added to android:configChanges

  • Testing in API 35
    • Works as expected: UI stringResource strings did change when switching language
    • Unexpected: screen flashes (completely black screen before showing changed UI string)
  • Testing in API 31 & API 24
    • Works as expected: UI stringResource strings did change when switching language
    • Works as expected: screen won't flash

With layoutDirection|locale|screenLayout added to android:configChanges

To fix the screen flash problem during language switching, I tried to add layoutDirection|locale to android:configChanges to <activity>

  • Testing in API 35
    • Works as expected: UI stringResource (string changed when switching language)
    • Works as expected: screen won't flash again
  • Testing in API 31 & API 24
    • Unexpected: UI stringResource strings didn't change when switching language (only the current language label of the language dropdown changed)
      • Testing in another application with AnimatedVisibility used: the string only changed to the switched language when they change their visibility
    • Works as expected: screen won't flash

Additional information

There are several articles mentioned attachBaseContext and onConfigurationChanged, but I couldn't find any up-to-date solution.

winstonsung avatar Feb 07 '25 10:02 winstonsung

Same problem here. stringResource is not updated correctly from api 24 to 33 when config change triggered (LocalConfiguration.current not updated...)

To manage configChanges, you must also add screenLayout to avoid black screen (screen flashes) So, you should haveandroid:configChanges="locale|layoutDirection|screenLayout"

jmartinMone avatar Feb 26 '25 15:02 jmartinMone