Mark Reload Previous Fragment In Back Stack Android

Many developers around the world faces the problem while using fragments when specially you are working with backstack. Let’s take an example when you have a Home fragment and display some information and another Fragment has ability to update, when you open Update fragment on top of it and putted HomeFragment to back stack, Your Next fragment performs some update tasks with apis now when you will press back button and your HomeFragment will be popped from backstack this will contains Old Information, but now you want to make api call to reload updated information.

There can be some more complex cases where you need to mark more than one or specific fragment in backstack.

I have already faced such issues in my production app, so i have build some basic and functionality to solve this.

Sharing with you the workaround

1. Create a MainActivity

activity_main.xml

1. Create class BaseFragment.java

3. Create HomeFragment.java

4. Create UpdateFragment.java

After building app with above code, you will see HomeFragment has a button to open next UpdateFragment.
Click OpenNextFragment button it will take to UpdateFragment and put current fragment in backstack.

I have added fragment in back stack with TagName, so that we could access by its tag.

You can see both Fragments extends BaseFragment class, having function to mark previous fragment for reloading by supplying TagName of the fragment.

I will put complete project code to download shortly, till the time enjoy reading and implementing it.

Categories: Android,Fragments

Leave A Reply

Your email address will not be published.