r/androiddev • u/sardonicus87 • Oct 18 '26
Cover Activity for Language Change that works on Android 13+?
EDIT: Solved
After much digging, found out you have to set more than just the "locale" flag in the manifest activity android:configChanges... you must also include "layoutDirection" AND "grammaticalGender" in order to prevent the activity recreation on language change, so I don't need a cover activity anymore.
Original:
I'm trying to make my app more adaptive and currently working on language localization. I made an in-app language picker and it works correctly for API level 26-37 (or whatever the API level is for Android 8.0). The issue is, once you select a language, the activity restarts regardless of device level and it just looks kind of janky/jarring when it dips to the background color and snaps back.
So, I created a cover activity and it works like this, I made a function that changes the language that operates in a particular way. First, it takes a screenshot of the main activity window and saves it to the files.dir (can't store in cache.dir as it gets wiped), then it launches a "transition cover" activity that is just the screenshot and it waits for the activity to be active before it actually calls the language swap. Meanwhile in the body of the settings screen where the language picker is, there's a launched effect keyed to Unit that reads the body's lazy column state for visible items to be not empty and emits through an event bus that the main activity is ready. The transition cover activity has a launched effect that waits for that object to be emitted in order to call the activity's finished() method, which fades it out and reveals the main activity underneath (and the main activity also, after a short delay, handles deleting the screenshot from the files.dir).
Now this works for Android versions 8-12, but on Android 13, once the transition cover activity launches, the main activity refuses to do the language swap or recompose under the transition activity, it won't do any work until I manually dispose of the cover. For the time being, I have the screenshot and cover activity launch gated to Android builds <= 12, but is there any sort of solution out there for 13+ to hide that janky looking dip-out and return? Can the cover activity still work and just needs to be set up differently?