# FragmentOnAttachListener

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

*** ** * ** ***


```
public interface FragmentOnAttachListener
```

<br />

*** ** * ** ***

Listener for receiving a callback immediately following `https://developer.android.com/reference/androidx/fragment/app/Fragment#onAttach(android.content.Context)`. This can be used to perform any additional setup / provide any dependencies that the Fragment may need prior to child fragments being attached or the Fragment going through `https://developer.android.com/reference/androidx/fragment/app/Fragment#onCreate(android.os.Bundle)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addFragmentOnAttachListener(androidx.fragment.app.FragmentOnAttachListener)` |   |

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener#onAttachFragment(androidx.fragment.app.FragmentManager,androidx.fragment.app.Fragment)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager fragmentManager, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment )` Called after the fragment has been attached to its host. |

## Public methods

### onAttachFragment

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

```
@MainThread
abstract void onAttachFragment(
    @NonNull FragmentManager fragmentManager,
    @NonNull Fragment fragment
)
```

Called after the fragment has been attached to its host. This is called immediately after `https://developer.android.com/reference/androidx/fragment/app/Fragment#onAttach(android.content.Context)` and before `https://developer.android.com/reference/androidx/fragment/app/Fragment#onAttach(android.content.Context)` has been called on any child fragments.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager fragmentManager` | FragmentManager the fragment is now attached to. This will be the same FragmentManager that is returned by `https://developer.android.com/reference/androidx/fragment/app/Fragment#getParentFragmentManager()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment` | Fragment that just received a callback to `https://developer.android.com/reference/androidx/fragment/app/Fragment#onAttach(android.content.Context)` |