Maybe the problem is simple, but anyway, I'm messing around to get it done. I know I would have to do this through interfaces, but I do not want it that way. My app has only a Activity
that houses many Fragments
. Activity
implements the Navigation Drawer
design pattern. It initially displays Fragment
. Think of it this way:
Fragment 1
> Fragment 2
> Fragment 3
> Fragment 4
.
Most Fragments
are lists. Now follow the sequence, I click on an item of Fragment 1
and I go to Fragment 2
, I click on an item of Fragment 2
and I go to Fragment 3
. Now in Fragment 3
, I press on an item, select an option (from a DialogFragment
and go to Fragment 4
.
My Fragment 4
is a screen that has data to be saved to the database and some of it is displayed in Fragment 3
. I have the option to edit this data and save, or else just access the Fragment 4
and do nothing, giving up saving and returning to Fragment 3
.
My problem is as follows: If I access the Fragment 4
and do not save, returning to Fragment 3
, nothing should happen, just the transaction back to normal even, that is, as the transaction is in Backstack
it will be rolled back. Now, if I access the Fragment 4
and save the data, I should go back to Fragment 3
and update the interface of it. For example, I go to Fragment 4
, after saving the data, I give a popBackStack()
and I go back to Fragment 3
updating its interface, instead of going back to Fragment 3
from where it left that is what happens .
I tried to do this with the public void onBackStackChanged()
method in Fragment 3
but this method is called whenever any change occurs in BackStack
, ie, I only access Fragment 3
from Fragment 2
it already is called.