Why might Resources.getString() intermittently return strings from the wrong locale?

后端 未结 3 1193
耶瑟儿~
耶瑟儿~ 2021-02-01 03:21

I have an Android application with English strings in values/strings.xml. For each string in that file, I have an entry in values-ja/strings.xml with the Japanese translation of

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 04:03

    Are you changing Locale while the application is running? If so, have you properly implemented the various elements of the Activity lifecycle (including onSaveInstanceState() and onRestoreInstanceState())?

    According to http://developer.android.com/guide/topics/resources/runtime-changes.html, a change in configuration at runtime should cause the Activity to be destroyed & restarted. It sounds like your app is noticing the new configuration but is not restarting properly (until restarting the whole App, or changing orientation).

    Are you doing anything funky in onSaveInstanceState or onDestroy?

    P.s. If it corrects itself only on certain orientation changes, can you advise if those orientation changes occur on layouts that have different vertical & horizontal layout files?

提交回复
热议问题