4.4 Sharing Data Between Fragments
Pass results between fragments
implementation 'androidx.fragment:fragment-ktx:1.5.0-beta01'override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Use the Kotlin extension in the fragment-ktx artifact
setFragmentResultListener("requestKey") { requestKey, bundle ->
// We use a String here, but any type that can be put in a Bundle is supported,
// remember that putExtra from intents uses a Bundle underlying, so anything
// you putExtra works here too!
val result = bundle.getString("bundleKey")
// Do something with the result
}
}Receiving results in Host Activity
Alternatives
Last updated
Was this helpful?