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

后端 未结 3 1276
耶瑟儿~
耶瑟儿~ 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

    This is just a theory but you could be leaking a Context. Basically, the old activity might be reporting the string values rather than the newly created on.

    A way to test this is:

    1. Change TAG to a member variable (NOT STATIC!).
    2. OnCreate, set TAG = this.toString(), this will put the memory address of the activity as the tag.
    3. Have the activity print out stuff using the initial locale.
    4. Do whatever to change the locale. This should (never verified this) restart the activity and you get a new activity. If you do. THen look at the log and see if the memory address is changing for the tag. If the memory address is the same as before the context was leaked.

提交回复
热议问题