'Android Navigation - Unable to get Saved State Handle from Dialog Destination
I am trying to pass data from dialog destination to fragment. But it is not getting called If I try the same consecutively. For single try it works fine.
Below is my code that is in my dialog fragment:
val navBackStackEntry = findNavController().getBackStackEntry(R.id.fragment_name)
onClick of button I am doing this
navBackStackEntry.savedStateHandle.set(ConstantUtils.SAVED_DATE, "")
dismiss()
In fragment's onResume I am observing the data like below:
val savedStateHandle = findNavController().currentBackStackEntry?.savedStateHandle
savedStateHandle?.getLiveData<String>(ConstantUtils.SAVED_DATE)?.observe(viewLifecycleOwner,
Observer { date ->
//Code goes here
savedStateHandle.remove<String>(ConstantUtils.SAVED_DATE)
})
When I click the button from dialog it comes to onResume of fragment, If I again go to the dialog and click on button it does not return to onResume of fragment.
Pleas let me know what mistake am I making here.
Solution 1:[1]
If you want to pass argument to fragment and receive one, you can use setFragmentResult() function can pass and receive bundle between fragments. This is source link for more study
https://developer.android.com/guide/fragments/communicate#fragment-result
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sajadab |
