# 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)

*** ** * ** ***


```
public static class 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 `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 `https://developer.android.com/reference/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 |
|---|
| `public fun interface https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.OnViolationListener` When `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy.Builder#penaltyListener(androidx.fragment.app.strictmode.FragmentStrictMode.OnViolationListener)` is enabled, the listener is called when a violation occurs. |
| `public final class https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy` `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode` policy applied to a certain `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` (or globally). |
| `public final class https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy.Builder` Creates `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy` instances. |

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode` | `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode#INSTANCE()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy` | `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode#getDefaultPolicy()()` The current policy for what actions should be detected, as well as the penalty if such actions occur. |
| `final void` | `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode#onPolicyViolation(androidx.fragment.app.strictmode.Violation)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/strictmode/Violation violation)` |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode#setDefaultPolicy(androidx.fragment.app.strictmode.FragmentStrictMode.Policy)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy value)` The current policy for what actions should be detected, as well as the penalty if such actions occur. |

## Public fields

### INSTANCE

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

```
public static @NonNull FragmentStrictMode INSTANCE
```

## Public methods

### getDefaultPolicy

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

```
public final @NonNull FragmentStrictMode.Policy getDefaultPolicy()
```

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

### onPolicyViolation

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

```
@VisibleForTesting
public final void onPolicyViolation(@NonNull Violation violation)
```

### setDefaultPolicy

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

```
public final void setDefaultPolicy(@NonNull FragmentStrictMode.Policy value)
```

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