Package dagger.hilt.android.flags
Class FragmentGetContextFix
java.lang.Object
dagger.hilt.android.flags.FragmentGetContextFix
Runtime flag for the Fragment.getContext() fix. See https://github.com/google/dagger/pull/2620
for this change. Controls if fragment code should use the fixed getContext() behavior where it
correctly returns null after a fragment is removed. This fixed behavior matches the behavior of a
regular, non-Hilt fragment and can help catch issues where a removed or leaked fragment is
incorrectly used.
In order to set the flag, bind a boolean value qualified with
FragmentGetContextFix.DisableFragmentGetContextFix
into a set in the SingletonComponent
. A set is used
instead of an optional binding to avoid a dependency on Guava. Only one value may be bound into
the set within a given app. If this is not set, the default is to not use the fix. Example for
binding the value:
@Module
@InstallIn(SingletonComponent.class)
public final class DisableFragmentGetContextFixModule {
@Provides
@IntoSet
@FragmentGetContextFix.DisableFragmentGetContextFix
static Boolean provideDisableFragmentGetContextFix() {
return // true or false depending on some rollout logic for your app
}
}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
Qualifier annotation to bind disable the Fragment.getContext() fix at runtime.static interface
Entry point for getting the flag. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isFragmentGetContextFixDisabled
(android.content.Context context)
-
Method Details
-
isFragmentGetContextFixDisabled
public static boolean isFragmentGetContextFixDisabled(android.content.Context context)
-