Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity

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?

like image 855
Carter Hudson Avatar asked Oct 13 '20 18:10

Carter Hudson


1 Answers

Without Hilt Dependencies we can access parent activity as below

(context as ContextWrapper).baseContext

like image 93
Shekhar Reddy Avatar answered Sep 19 '22 08:09

Shekhar Reddy