You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I have the following configuration using Hilt 2.32-alpha, I set up the annotation @androidentrypoint on a Fragment. This fragment declares a custom view in its layout.
The problem occurs when I was trying to get context (basically activity) from inside the Custom view class and I'm getting FragmentContextWrapper: this class is not intended to be used outside the Hilt components as mentioned in the documentation.
So I'm trying to figure out how to get the context correctly or if I'm doing something wrong in the hilt implementation?
Otherwise, I want to verify if this is a known bug in the hilt implementation.
Thank you for your help.
Rahul
The text was updated successfully, but these errors were encountered:
In general, you shouldn't assume that a context is exactly a particular object like the Activity. You should only assume that a context eventually wraps the Activity. This is true even without Hilt since Android does have context wrappers for themes for example. To get the activity from the view, you should take the context, check if it is the Activity, and if not, unwrap it by getting its base context, and repeating and until you find the Activity.
Hello,
I have the following configuration using Hilt 2.32-alpha, I set up the annotation @androidentrypoint on a Fragment. This fragment declares a custom view in its layout.
The problem occurs when I was trying to get context (basically activity) from inside the Custom view class and I'm getting FragmentContextWrapper: this class is not intended to be used outside the Hilt components as mentioned in the documentation.
So I'm trying to figure out how to get the context correctly or if I'm doing something wrong in the hilt implementation?
Otherwise, I want to verify if this is a known bug in the hilt implementation.
Thank you for your help.
Rahul
The text was updated successfully, but these errors were encountered: