How to check if phone locale has changed?
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 a开发者_如何转开发pplication. 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()
?
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;
}
}
精彩评论