views:

23

answers:

1

Assume an application that has some locale-based raw resources. But the resources are not "corrensponding" to each other - one locale has less resources than another one. Application stores it's state when closed.

So, user can launch the application in one locale, close it (app remembers its state), then user changes phone locale, and restores the application. App tries to retrieve raw resource, but fails, because some information in that raw resource is missing due to another locale.

The question is: how to store current locale when closing the application?

I know about java.util.Locale, but how can I put Locale to the Bundle? Can I rely on getLanguage()?

+1  A: 

You can store current locale info into Preference when user close app.

Following is the sample code of how to access current local:

public class Activity() {
    public getLocal() {
        return getResources().getConfiguration().locale;
    }
}
Tony
Thanks. After getResources().getConfiguration().locale I get a Locale object. SharedPreferences editor allows to put int/boolean/float/long or a string. What is the most correct way to convert Locale (to a string, I guess?)
zserge
There are two part in Locale object: country and language, I think, in your case, what you need is country, so use Locale.getCountry() may work fine.
Tony