Update fragment UI after returning from BackStack

1

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.

    
asked by anonymous 11.06.2014 / 16:13

1 answer

1

I solved my problem using Custom Loader for my Custom Adapter . The difficulty was only to implement Loader , but thanks to this implementation, it was not necessary to communicate a Fragment with another or with Activity . When I was in Fragment and returned to the other Fragment through popBackStack() , the loader simply reloads updating the data.

If you want to understand a little more about Loaders see here.

    
23.06.2014 / 02:51