The Kotlin sharing data using fragment interface Android development tutorial describes how to pass data from a fragment to an Activity using a fragment interface.
The Kotlin on Android example application will capture a video in one Android fragment. The Uri of the captured video will then be passed to the calling activity.
The video capture portion of the Kotlin on Android tutorial will be based on the Kotlin Video tutorial.
If you are new to Android and/or Kotlin I recommend the Kotlin Fragments series to be done prior to this Kotlin on Android tutorial.
The key concepts this Kotlin on Android tutorial will cover are
- Creating Android fragment including layout files and interface
- How to use Android fragment tags
- How to load an Android fragment from an Android activity
- Getting the Uri of a recorded video
- How create an interface in an Android fragment
- How to implement a fragment interface in an Android Activity
In this Kotlin on Android tutorial we will cover:
Episodes
Conclusion
In this Kotlin on Android development tutorial, we described a common method of returning data from an Android Fragment to an Android Activity.
And for the tutorial example, we used the captured video, Uri.
Android studio was used to create the Android fragment along with the interface. As well as the creation of the interface, the implementation of the fragment’s onAttach method is created. Which initializes the interface and also checks that the calling activity has implemented the fragment interface.
In the following Kotlin on Android tutorial, we will describe how to pass data from an Android activity to an Android Fragment.