I have implemented custom locale selection about a year ago but after 4.1 release users start to complain on constant activity blinking. Here is code I'm using (compiled from different SO answers):
public final class TestApplication extends Application
{
private Locale desiredLocale = new Locale("ru-RU");
@Override
public void onCreate() {
super.onCreate();
updateLocale(new Configuration());
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
updateLocale(newConfig);
}
private void updateLocale(Configuration newConfig) {
newConfig.locale = desiredLocale;
Locale.setDefault(desiredLocale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
Application contains only one empty activity, which is recreated by Android every second after I change device orientation. Here is the source of sample.
It looks like all applications which use this technique became invalid. What is the correct approach?