FragmentStrictMode.Policy.Builder

public final class FragmentStrictMode.Policy.Builder


Creates Policy instances. Methods whose names start with detect specify what problems we should look for. Methods whose names start with penalty specify what we should do when we detect a problem.

You can call as many detect and penalty methods as you like. Currently order is insignificant: all penalties apply to all detected problems.

Summary

Public constructors

Public methods

final @NonNull FragmentStrictMode.Policy.Builder
allowViolation(
    @NonNull Class<@NonNull Fragment> fragmentClass,
    @NonNull Class<@NonNull Violation> violationClass
)

Allow the specified Fragment class to bypass penalties for the specified Violation, if detected.

final @NonNull FragmentStrictMode.Policy

Construct the Policy instance.

final @NonNull FragmentStrictMode.Policy.Builder

Detects cases, where a Fragment instance is reused, after it was previously removed from a FragmentManager.

final @NonNull FragmentStrictMode.Policy.Builder

Detects usage of the tag inside XML layouts.

final @NonNull FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setRetainInstance and Fragment.getRetainInstance.

final @NonNull FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setUserVisibleHint.

final @NonNull FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setTargetFragment, Fragment.getTargetFragment and Fragment.getTargetRequestCode.

final @NonNull FragmentStrictMode.Policy.Builder

Detects cases where a Fragment is added to a container other than a androidx.fragment.app.FragmentContainerView.

final @NonNull FragmentStrictMode.Policy.Builder

Throws an exception on violation.

final @NonNull FragmentStrictMode.Policy.Builder

Call OnViolationListener.onViolation for every violation.

final @NonNull FragmentStrictMode.Policy.Builder

Log detected violations to the system log.

Public constructors

Builder

public final Builder()

Public methods

allowViolation

@NonNull
public final FragmentStrictMode.Policy.Builder allowViolation(
    @NonNull Class<@NonNull Fragment> fragmentClass,
    @NonNull Class<@NonNull Violation> violationClass
)

Allow the specified Fragment class to bypass penalties for the specified Violation, if detected.

By default, all Fragment classes will incur penalties for any detected Violation.

build

@NonNull
public final FragmentStrictMode.Policy build()

Construct the Policy instance.

Note: if no penalties are enabled before calling build, penaltyLog is implicitly set.

detectFragmentReuse

@NonNull
public final FragmentStrictMode.Policy.Builder detectFragmentReuse()

Detects cases, where a Fragment instance is reused, after it was previously removed from a FragmentManager.

detectFragmentTagUsage

@NonNull
public final FragmentStrictMode.Policy.Builder detectFragmentTagUsage()

Detects usage of the tag inside XML layouts.

detectSetUserVisibleHint

@NonNull
public final FragmentStrictMode.Policy.Builder detectSetUserVisibleHint()

Detects calls to Fragment.setUserVisibleHint.

detectWrongFragmentContainer

@NonNull
public final FragmentStrictMode.Policy.Builder detectWrongFragmentContainer()

Detects cases where a Fragment is added to a container other than a androidx.fragment.app.FragmentContainerView.

penaltyDeath

@NonNull
public final FragmentStrictMode.Policy.Builder penaltyDeath()

Throws an exception on violation. This penalty runs at the end of all enabled penalties so you'll still get to see logging or other violations before the exception is thrown.