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 6068231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:41:35+00:00 2026-05-23T09:41:35+00:00

I would like the application language to be set according to the user preferences

  • 0

I would like the application language to be set according to the user preferences but up till now it doesn’t work how I would like it to.

I have set the default values: strings.xml and also values-es with a strings.xml inside in spanish. I have a menu option which brings the user to a Preference activity where he can amon gother things chose the language.

So here are some extracts of the code:

public class Preference extends PreferenceActivity implements
        OnSharedPreferenceChangeListener {
......
// Set up a listener whenever a key changes 
        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);


...}
//(......)

//and here I have the listener so when the language pref changes value the locale gets changed.
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
        if (key.equals("listPref2")) {
            String idioma = sharedPreferences.getString("listPref2", "catala");
            if ("castella".equals(idioma)) {
                idioma = "es_ES";

                Locale locale = new Locale(idioma);
                Locale.setDefault(locale);
                Configuration config = new Configuration();
                config.locale = locale;
                getApplicationContext().getResources().updateConfiguration(config,
                        getBaseContext().getResources().getDisplayMetrics());
            }
        }
    }

So when I change the language it works but then when I come back later or restart the emulator the language gets back to default locale the en_US and the app language gets changed back to default again. What can I do to sort that out?

I know I can get this preference (which I can access to from all my activities) and then each time set up the locale but I find it a bit heavy isn’t there a way to do it in a more elegant way?

What I would like to do is if the user sets up the language so when he comes back 2 days later he doesn’t have to change the language again.

Any ideas?

  • 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-05-23T09:41:36+00:00Added an answer on May 23, 2026 at 9:41 am

    OK it may help someone. I have added the folowing to the main activity manifest:

    android:configChanges="locale"

    Then when the user choses the preferences I have put a confirm button and then this button brings you to main activity that is why the lnagages gets reset.

    I have a static class where I have this code to change the locale:

    public static void updateLanguage(Context context, String idioma) {
        if (!"".equals(idioma)) {
            if ("castella".equals(idioma)) {
                idioma = "es_ES";
            } else if ("catala".equals(idioma)) {
                idioma = "ca_ES";
            }
            Locale locale = new Locale(idioma);
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            context.getResources().updateConfiguration(config, null);
        }
    }
    

    end at every activity I have like 20 of them I call this method before:

    setContentView(R.layout.list_event);

    With these methods when I rotate the screen the activities don’t change the language
    here is a link to a blog that helped me:
    http://adrianvintu.com/blogengine/post/Force-Locale-on-Android.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a customer that would like to modify application user messages that we
I have developed about 300 Applications which I would like to provide with multi-language
I would like my application to look similar to that of the Windows version:
I would like an application which is not readily apparent to casual perusal of
I would like a web application to learn things about its environment so that
My client would like a business application to support 'every possible device'. The application
In SCSF application I would like to display a view as a modal window
I would like to create an application wide keyboard shortcut for a Java Swing
I would like to create an application that runs on XBox 360 (downloaded using
I would like to make my application somewhat REST compliant. I am using Rails

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.