0

My application is running with two language i.e English and Spanish, For this i maintain two folders for values i.e values and values-sp.

I have one button in my SettingsActivity when ever i clicked on that the total application changed to selected language for that i have written the attached code.

My Problem is when ever i clicked the button and press back button app is showing black screen for some time then it is appearing.

in every activity of on resume i am calling onCreate again for refreshing view. even though i have done this the black screen is appearing.

Can any one please help me to get out of this.

Thanks in advance.

My code is

english.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) 
                {
                       languagePopup.dismiss();
                       Locale locale2 = new Locale("en"); 
                       Locale.setDefault(locale2);
                       Configuration config2 = new Configuration();
                       config2.locale = locale2;
                       getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
                       changLanguae();
                       if(language.equalsIgnoreCase("English"))
                           Constants.isLanguageChanged=false;
                       else
                           Constants.isLanguageChanged = true;

                }
            });
            spanish.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v)
                {
                       languagePopup.dismiss();
                       Locale locale2 = new Locale("es"); 
                       Locale.setDefault(locale2);
                       Configuration config2 = new Configuration();
                       config2.locale = locale2;
                       getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
                       changLanguae();
                       if(language.equalsIgnoreCase("Spanish"))
                           Constants.isLanguageChanged=false;
                       else
                           Constants.isLanguageChanged = true;

                }
            });
user1430138
  • 11
  • 1
  • 6

2 Answers2

1

Create a method in which the view's value setting part is copied and use this method on your onResume().no need to write the whole onCreate in onResume()

Abx
  • 2,852
  • 4
  • 30
  • 50
1

A nicer way to go about language change for an app is to let user change the language and input settings from device settings and let the device and app handle appropriately this change by rendering UI from your created folders for that language. An example is at Android Localization.

Prasad
  • 349
  • 2
  • 6