# FragmentOnAttachListener

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

*** ** * ** ***

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

<br />

```
interface FragmentOnAttachListener
```

<br />

*** ** * ** ***

Listener for receiving a callback immediately following[onAttach](https://developer.android.com/reference/kotlin/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[onCreate](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#onCreate(android.os.Bundle)).  

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

## Summary

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onAttachFragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentOnAttachListener#onAttachFragment(androidx.fragment.app.FragmentManager,androidx.fragment.app.Fragment))`(fragmentManager: `[FragmentManager](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager)`, fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment)`)` Called after the fragment has been attached to its host. |

## Public functions

### onAttachFragment

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

```
@MainThread
fun onAttachFragment(fragmentManager: FragmentManager, fragment: Fragment): Unit
```

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

|                                                         Parameters                                                         |
|----------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fragmentManager: `[FragmentManager](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager) | FragmentManager the fragment is now attached to. This will be the same FragmentManager that is returned by[getParentFragmentManager](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#getParentFragmentManager()). |
| `fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment)                      | Fragment that just received a callback to[onAttach](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#onAttach(android.content.Context))                                                                            |