# FragmentStrictMode

# FragmentStrictMode

Artifact:[androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment)  
[View Source](https://cs.android.com/search?q=file:androidx/fragment/app/strictmode/FragmentStrictMode.kt+class:androidx.fragment.app.strictmode.FragmentStrictMode)  
Added in[1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode "View this page in Java")

<br />

```
object FragmentStrictMode
```

<br />

*** ** * ** ***

FragmentStrictMode is a tool which detects things you might be doing by accident and brings them to your attention so you can fix them. Basically, it's a version of[android.os.StrictMode](https://developer.android.com/reference/android/os/StrictMode.html)specifically for fragment-related issues.

You can decide what should happen when a violation is detected. For example, using[Policy.Builder.penaltyLog](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy.Builder#penaltyLog())you can watch the output of`adb logcat`while you use your application to see the violations as they happen.

## Summary

|                                                                                                                                                                                                                                       ### Nested types                                                                                                                                                                                                                                       |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fun interface `[FragmentStrictMode.OnViolationListener](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.OnViolationListener) When[Policy.Builder.penaltyListener](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy.Builder#penaltyListener(androidx.fragment.app.strictmode.FragmentStrictMode.OnViolationListener))is enabled, the listener is called when a violation occurs. |
| `class `[FragmentStrictMode.Policy](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy) [FragmentStrictMode](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode)policy applied to a certain[FragmentManager](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager)(or globally).                                                                      |
| `class `[FragmentStrictMode.Policy.Builder](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy.Builder) Creates[Policy](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy)instances.                                                                                                                                                                                          |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[VisibleForTesting](https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting) [onPolicyViolation](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode#onPolicyViolation(androidx.fragment.app.strictmode.Violation))`(violation: `[Violation](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/Violation)`)` |

|                                                         ### Public properties                                                          |
|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [FragmentStrictMode.Policy](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode.Policy) | [defaultPolicy](https://developer.android.com/reference/kotlin/androidx/fragment/app/strictmode/FragmentStrictMode#defaultPolicy()) The current policy for what actions should be detected, as well as the penalty if such actions occur. |

## Public functions

### onPolicyViolation

Added in[1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)  

```
@VisibleForTesting
fun onPolicyViolation(violation: Violation): Unit
```  

## Public properties

### defaultPolicy

Added in[1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)  

```
var defaultPolicy: FragmentStrictMode.Policy
```

The current policy for what actions should be detected, as well as the penalty if such actions occur.