How to reopen a fragment with saved instance from another fragment?

I have 1 activity with multiple fragments. These fragments call each other, for example fragment a calls fragment b:

Fragment a:

FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, new FragmentB());
ft.commit();

Where OrderAddFragment is fragment b.

Now, let's say a user has filled in multiple inputs in fragment a and continues to fragment b but than he realises he made a mistake in fragment a and needs to go back to correct this mistake.

How could I reopen fragment a with the saved instance state instead of creating a new instance?

The back function in fragment b uses following code to reopen fragment a:

FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, new FragmentA());
ft.commit();

Answers


FragmentTransaction.addToBackStack() might solve your problem.


Need Your Help

Deploy VSTO Document solution to Excel 2003

c# ms-office vsto office-2003

We have an Excel workbook which has c# VSTO code in it and two .NET DLLs that sit behind it. The spreadsheet used to work for all users in the organisation.