Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Use Kodein instance in attachBaseContext? #2

Open
mayumipal opened this issue Jun 25, 2021 · 0 comments
Open

How to Use Kodein instance in attachBaseContext? #2

mayumipal opened this issue Jun 25, 2021 · 0 comments

Comments

@mayumipal
Copy link

mayumipal commented Jun 25, 2021

class MainActivity : AppCompatActivity(), KodeinAware {

override val kodein by kodein()
private val dataHandler: DataHandler by instance()

override fun attachBaseContext(newBase: Context?) {
        val appLanguage = dataHandler.getLanguage()
    super.attachBaseContext(MyContextWrapper.wrap(newBase,appLanguage ))
}

}

I need to access my SharedPreferences instance in the attachBaseContext of my activity (so I can set the locale there), but the injected SharedPreferences instance is not available there as the injection is happening in the onCreate method, which is running after the attachBaseContext call. I am using kodein , android studio, kotlin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant