Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:47:06+00:00 2026-06-10T16:47:06+00:00

i have one activity and in onCreate i load language from preferences and set

  • 0

i have one activity and in onCreate i load language from preferences and set a locale like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String lang = PreferenceManager.getDefaultSharedPreferences(this).getString("locale", "en");
    Locale newLocale = new Locale(lang);
    Locale.setDefault(newLocale);

    Configuration config = new Configuration();
    config.locale = newLocale;

    final Resources res = getResources();
    res.updateConfiguration(config, res.getDisplayMetrics());
}

i also override onConfigurationChanged

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    String lang = PreferenceManager.getDefaultSharedPreferences(this).getString("locale", "en");
    Locale newLocale = new Locale(lang);
    Locale.setDefault(newLocale);

    Configuration config = new Configuration();
    config.locale = newLocale;

    final Resources res = getResources();
    res.updateConfiguration(config, res.getDisplayMetrics());
}

i have a ViewPager with FragmentPagerAdapter and three tabs on android 2.3.7. the problem is, that sometimes when switching the tabs the app’s locale gets reverted back to english, so the UI has mixed languages from now on. i always create new fragments for the tabs in adapter’s getItem() method. if i rotate the device the locale is correct again.

i also tried putting android:configChanges=”locale” in manifest and not overriding onConfigurationChanged(), but the result is the same.

the worst thing is, that it is not 100% reproducible, it happens only some times and i also have reports from users about this. once the application starts and it do not change the locale after switching few tabs, then it will correctly until exit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:47:08+00:00Added an answer on June 10, 2026 at 4:47 pm

    After some time I figured out a way. The only solution that works for me is always setting the locale in main Acitivity’s onCreate(), in each Fragment’s onCreateView(), in onReceive() of every BroadcastReceiver() (if it loads some resource) and at the start of every Service. For this I made a static method setLocale() in my main and only activity. If you have more activities it could be placed in a custom Application class.

    One last thing. Even this some times does not work if the app is started directly from IDE for debugging. Do not worry, it works (at least for me) if it is run normally on the device.

    public static void setLocale(Context context) {
        final String lang = PreferenceManager.getDefaultSharedPreferences(context).getString("locale", "en");
        final Locale newLocale = new Locale(lang);
        Locale.setDefault(newLocale);
        final Configuration config = new Configuration();
        config.locale = newLocale;
    
        final Resources res = context.getResources();
        res.updateConfiguration(config, res.getDisplayMetrics());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a design of activities like this I have one main activity and
Within one Activity I have th following piece of code: public void onStartMonitoringToggleClicked(View v)
I have following function in one Activity public void AppExit() { Editor edit =
My one activity seems to have grown quite a bit and I feel like
I have one SubjectTabActivity and i need to show listview on this activity. But
I have an ArrayList of objects in one activity and I need this arrayList
I have created one activity And I write some functions inside onCreate() function. On
I have an Activity that retrieves data from a web service. This data is
I have one activity. OnCreate the activity gets the source (html) of a web
I have one superclass in my android project that inherits from activity and implements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.