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(
    Class<Fragment> fragmentClass,
    Class<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

public final @NonNull FragmentStrictMode.Policy.Builder allowViolation(
    Class<Fragment> fragmentClass,
    Class<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

public final @NonNull FragmentStrictMode.Policy build()

Construct the Policy instance.

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

detectFragmentReuse

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

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

detectFragmentTagUsage

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

Detects usage of the tag inside XML layouts.

detectSetUserVisibleHint

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

Detects calls to Fragment.setUserVisibleHint.

detectWrongFragmentContainer

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

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

penaltyDeath

public final @NonNull 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.

penaltyListener

public final @NonNull FragmentStrictMode.Policy.Builder penaltyListener(FragmentStrictMode.OnViolationListener listener)

Call OnViolationListener.onViolation for every violation. The listener will be called on the main thread of the fragment host.