android / codelab-android-hilt

Apache License 2.0
348 stars 184 forks source link

Problem when getting context in android Custom View inflated in Fragment #14

Open EssidM opened 3 years ago

EssidM commented 3 years ago

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 it's 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 this is a know bug in the hilt implementation.

Thank for your help. Messid

manuelvicnt commented 3 years ago

I think this issue should be filed in https://github.com/google/dagger if this is still happening. Can you inject @ActivityContext?

abrolrahul commented 2 years ago

Filed it in https://github.com/google/dagger/issues/3417