mohamadreza jafarzade
09/06/2020, 11:19 AMaddToBackstack()
would help me but it is only responsible for previous fragment not the new one.rkeazor
09/06/2020, 12:25 PMJorge Castillo
09/06/2020, 3:11 PMpopupTo
/ popupToInclusive
. https://developer.android.com/guide/navigation/navigation-navigatemohamadreza jafarzade
09/06/2020, 3:13 PMIan Lake
09/06/2020, 4:22 PMmohamadreza jafarzade
09/06/2020, 4:41 PMNavigation Component
but because of force of our project, I can not do that in this time.
I just do that in a weird way. I started activity B from fragment y by calling startActivityForResult()
and then when i press back in activity B, I call setResult(RESULT_OK)
Then in fragment y i do this:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE){
parentFragmentManager.popBackStack (this::class.java.name,
FragmentManager.POP_BACK_STACK_INCLUSIVE)
}
}
Actually, I use class names as their name in backstack.
I know this is not good way, but at least it works for me :)Ian Lake
09/06/2020, 5:34 PMRESULT_OK
), but you don't seem to have any condition like that so putting your Activity A in the right state ahead of time is going to 1) remove the need to save and restore Fragment y at all 2) set you up for animations, transitions (which would not be easy if you do this just in time approach)