views:

508

answers:

2

I try to force the locale in my app to one the user specified. As this may be used to demonstrations, I want to change the language/locale in the app and not anytime for the whole device.

I looked around SO and tried to use every hint I found here. The result: I can restart my test activity with the new language, but if I change the orientation, the locale will always be reseted to the device one.

I uploaded a minimalistic project so you can reproduce my issue. Please ignore the shrinking of the UI, its not important :)

+1  A: 

Is the reset of the locale occurring because your Activity is being restarted on orientation change?

If so, you can intercept or prevent orientation changes: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android

Scott Smith
I "restart" my Activity with finish() and startActivity() to force the reload of the UI which use the new locale. The orientation change always resets my locale
WarrenFaith
A: 

I just saw your code.

Check that the Locale you are using is from java.util and not from android. Your code will not change the locale of the cellphone.

To test it:

  • I set my phone to Spanish.
  • Open your app
  • click the button
  • go to home
  • Icons were in spanish instead of english.

If what you are trying to do is just setting the Locale to a default and being able to see the same value after a screen rotation:

Instead of:

android:configChanges="locale"

use:

android:configChanges="locale|orientation"
Macarse