-
Notifications
You must be signed in to change notification settings - Fork 154
Not working in combination with dagger hilt #128
Comments
I have sample code for Dagger Hilt implementation See ApplicationContext was injected with Feel free to tell me more information if part of your code that different from my sample code |
OK I will test this later and tell you if it worked. EDIT: I think I know where the problem lies. I didn't test this, but what about classes that live as Singletons and have an applicationContext injected into them? Classes such as Repositories annotated with I observed the following: When I change the language, the applicationContext inside my singleton classes doesn't get updated. But when I now restart the app, the applicationContext is updated because the app has been newly created. Might this be the Issue @akexorcist ? |
Since AndroidX AppCompat has per-app language preferences for backward compatibility. Please migrate this library to AndroidX for more stability, compatibility, and longer support from Google team. Thank you for your support |
I wanted to use this library in combination with dagger-hilt, but that does not seem to work. To be more specific:
There is a dagger-hilt annotation called
@ApplicationContext
, with which we can inject the application context inside every possible non-android-class. Here is an example:Now comes the problem: When switching languages, this
ApplicationContext
does not seem to update. For example, let's say we have two versions of the above string:German "R.string.stuff" -> Hallo
English "R.string.stuff" -> Hello
When you now change the language from german to english in Fragment with
(requireActivity as LocaleAwareCompatActivity).updateLocal(Locale.EN)
, then the following happens:Calling
requireContext().getString(R.string.stuff)
in Fragment gives "Hello" (language was updated correctly). But inside my Repository "R.string.stuff" is still "Hallo" (language was not updated correctly)The text was updated successfully, but these errors were encountered: