In my android app I am trying to implement the in app language with a new way (for API>=33 and backwards compatibility).
I also created xml config file, added things to manifest, etc, but this is the code itself:
lng = Resources.getSystem().getConfiguration().getLocales().get(0).getLanguage();
LocaleListCompat appLocale = LocaleListCompat.forLanguageTags(lng);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
overrideActivityTransition(Activity.OVERRIDE_TRANSITION_OPEN,0,0);
} else {
overridePendingTransition(0, 0);
}
AppCompatDelegate.setApplicationLocales(appLocale);
So when the app starts, it takes device language and set the app language.
Then also switching in app languages works fine.
Question 1: For API>=33, the user can select app language in Device System -> App language.
How to obtain this value?
Question 2: AppCompatDelegate.setApplicationLocales(appLocale) also restarts the activity and I noticed a black screen during this (I tried on emulator with APi33, did not notice on real device with API 32).
For that reason I used overridePendingTransition (it is deprecated for API>=34, that's why I used this condition, but it doesn't matter now):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
overrideActivityTransition(Activity.OVERRIDE_TRANSITION_OPEN,0,0);
} else {
overridePendingTransition(0, 0);
}
This however doesn't help.