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?
If the third-party library has an issue tracker, it's a good idea to raise an issue about this. There is no guarantee that the
context
of aView
is anActivity
: the same problem can be caused just as easily by anandroid:theme
attribute in the custom view or any ancestor.If you don't inflate any
@AndroidEntryPoint
views in your fragment, you can work around this by getting aLayoutInflater
directly from the activity context.