androidlocalizationandroid-jetpack-composelocaleandroid-appcompat

How to prevent screen "flash" on locale change in Jetpack Compose with AppCompatDelegate?


I added an In-app language picker for my Compose App following this article. but everytime I change the language the screen flashes. I guess it is due to configuration changes

I downloaded the sample app out of curiosity and it has the same issue.

Is there a way to prevent these "flashes" or add a nice transition animation? Ideally I would like to just reload the string resources

Here is a gif about the issue

I tried overwriting the recreate() method in the MainActivity and editing the androidmanifest file based on these couldn't prevent the "flash" : How do I keep my android activity keep on going even if somebody switches from dark mode to day mode or vice versa (using Java) How to trigger recomposition after updateConfiguration?


Solution

  • I figured out the solution for this:

    Short answer: Add this line to your AndroidManifest.xml activity tag

    android:configChanges="locale|layoutDirection"
    

    Long answer: Read these: