androidandroid-fragmentsandroid-dialogfragmentbottom-sheet

Pass data from BottomSheetFragment to previous Fragment


Is there any better way to send back the data to the previous fragment/parent fragment other than listener?

I have a fragment which consists of list of items. Clicking on the items will open a bottom sheet fragment. While closing the bottom sheet popup I need to pass data back to the fragment itself.

What I have done so far is created a listener and implemented it.


Solution

  • It really depends on what components you're using. If you are using Android Jetpack components then check out this article: LINK

    You should be able to pass data back and forth similar to passing data with startActivityForResult()

    Also, while you're at it please check out the official documentation too, there's a good example that will help you understand this better: LINK