android / codelab-android-hilt

Apache License 2.0
350 stars 186 forks source link

FragmentContextWrapper cannot be cast to android.app.Activity #7

Closed carterhudson closed 3 years ago

carterhudson commented 3 years ago

I'm using a third-party library that has some custom view implementations. In the implementation, they call Utils.showSoftKeyboard(context as Activity). This, along with using the fragment as an @AndroidEntryPoint causes the following exception java.lang.ClassCastException: dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity. Is there any way to fix this without altering the third-party library?

manuelvicnt commented 3 years ago

Hi! Has the third-party library migrated to AndroidX? That might be the issue

devprithvi commented 2 years ago

//<>****Without Hilt Dependencies we can access parent activity as below**** val context = (context as ContextWrapper).baseContext

khalidabdou commented 2 years ago

use requireActivity() instead activity