My android application depends on some library that behaves wrongly on changing the language of the phone to some arabic language. So I want my app locale to remain locale.US. For that, I searched and found the following code in MainApplication:
public class MyApplication extends Application
{
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
Locale.setDefault(Locale.US);
newConfig.locale = Locale.US;
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
@Override
public void onCreate()
{
locale = Locale.US;
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
}
This code creating problem on android L. When I change the language of the phone to arabic, the onConfigurationChanged
function is called single times , but the activity keeps on getting created after opening the app. It looks like it is creating in a loop. So,
- Can I use
Locale.setDefault(Locale.US)
withoutgetBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
as it is working correctly. - Is there any other way to specify the locale of the android app.