{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FragmentStrictMode.Policy.Builder

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 functions

FragmentStrictMode.Policy.Builder
allowViolation(
    fragmentClass: Class<Fragment>,
    violationClass: Class<Violation>
)

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

FragmentStrictMode.Policy.Builder
allowViolation(fragmentClass: String, violationClass: Class<Violation>)

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

FragmentStrictMode.Policy

Construct the Policy instance.

FragmentStrictMode.Policy.Builder

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

FragmentStrictMode.Policy.Builder

Detects usage of the tag inside XML layouts.

FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setRetainInstance and Fragment.getRetainInstance.

FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setUserVisibleHint.

FragmentStrictMode.Policy.Builder

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

FragmentStrictMode.Policy.Builder

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

FragmentStrictMode.Policy.Builder

Throws an exception on violation.

FragmentStrictMode.Policy.Builder

Call OnViolationListener.onViolation for every violation.

FragmentStrictMode.Policy.Builder

Log detected violations to the system log.

Public constructors

Builder

Builder()

Public functions

allowViolation

fun allowViolation(
    fragmentClass: Class<Fragment>,
    violationClass: Class<Violation>
): FragmentStrictMode.Policy.Builder

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.

allowViolation

fun allowViolation(fragmentClass: String, violationClass: Class<Violation>): FragmentStrictMode.Policy.Builder

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

Since this overload of allowViolation takes in the name of the Fragment class as a string, rather than accepting the Class itself, the user will need to manually insure the class is not obfuscated.

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

build

fun build(): FragmentStrictMode.Policy

Construct the Policy instance.

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

detectFragmentReuse

fun detectFragmentReuse(): FragmentStrictMode.Policy.Builder

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

detectFragmentTagUsage

fun detectFragmentTagUsage(): FragmentStrictMode.Policy.Builder

Detects usage of the tag inside XML layouts.

detectRetainInstanceUsage

fun detectRetainInstanceUsage(): FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setRetainInstance and Fragment.getRetainInstance.

detectSetUserVisibleHint

fun detectSetUserVisibleHint(): FragmentStrictMode.Policy.Builder

Detects calls to Fragment.setUserVisibleHint.

detectTargetFragmentUsage

fun detectTargetFragmentUsage(): FragmentStrictMode.Policy.Builder

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

detectWrongFragmentContainer

fun detectWrongFragmentContainer(): FragmentStrictMode.Policy.Builder

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

penaltyDeath

fun penaltyDeath(): FragmentStrictMode.Policy.Builder

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

fun penaltyListener(listener: FragmentStrictMode.OnViolationListener): FragmentStrictMode.Policy.Builder

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

penaltyLog

fun penaltyLog(): FragmentStrictMode.Policy.Builder

Log detected violations to the system log.