The Kotlin sharing data using fragment arguments Android development tutorial describes how to pass data from an Android activity to a fragment using arguments.
This Kotlin on Android tutorial follows directly on from the passing data from android fragment to activity tutorial.
The recorded Uri from the previous tutorial will be passed from the main activity to a new Android fragment. Which will load the Uri into a VideoView for playback.
The video playback portion of the Kotlin on Android tutorial will be based on the Kotlin VideoView 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 Fragments including layout files
- How to load an Android fragment from an Android activity
- How to switch from one Android fragment to another Android fragment
- How to pass data from an Android activity to fragment
- How to impement a VideoView in an Android fragment
In the Kotlin fragment arguments data share Android development tutorial, we described how to pass data from an Android activity to an Android fragment.
Inside the VideoViewFragment the fragment’s argument value was used to save the Uri. Which could then be reused inside the fragment lifecycle.
A basic VideoView was also implemented inside the Android fragment, for video playback.
As demonstrated in this and the previous tutorial, a significant amount of code was required for the implementation for sharing data between Android fragments.
In the following tutorial, we will describe an alternative approach, using the Android ViewModel.