This is sequence of my fragment call logic
call A bottomsheetfragment
on A bottomsheetfragment, call B bottomsheetfragment
I must send data on B bottomsheetfragment to A bottomsheetfragment
I use Livedata : set Livedata on B bottomsheetfragment and observe A bottomsheetfragment
-> can't observe
I wonder how I can send B data to A
Use livedata
Use fragment bundle, arguments
This is code
call fragment A
private fun initAddSchedulebutton(){
binding.btnFragmentCalendarAddSchedule.setOnClickListener {
AddScheduleBottomSheetDialogFragment().also {
it.show(
requireActivity().supportFragmentManager,
it.tag,
)
}
}
}
call fragment B on fragment A
private fun initSearchLocationButton() {
binding.tvDialogCreateScheduleSearchLocation.setOnClickListener {
SearchLocationDialog().also {
it.show(
requireActivity().supportFragmentManager,
it.tag,
)
}
}
}
when I select address on google map, I must send address date on fragment B to fragment A
private fun initSelectButton(){
binding.tvDialogSearchLocationSelectLocation.setOnClickListener {
dismiss()
}
}
when fragment B called on fragment A, I can guessed fragment A's lifecycle is onViewCreated, so I can't use arguments, because fragment A already initialized. Also viewModel is destroyed when fragment B destroyed, so I can't observe live data in fragment A