I have 2 Fragments
F1 and F2. I open the first Fragment
F1 from the Activity
using the following code:
MyFragment f1 = new MyFragment();
Bundle bundle = new Bundle();
bundle.putString("GameLevelType", "Learn");
dialog.setArguments(bundle);
FragmentTransaction gameTransaction = getSupportFragmentManager().beginTransaction();
gameTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
gameTransaction.add(android.R.id.content, f1).addToBackStack(null).commit();
Then from Fragment
F1 I am opening another Fragment
F2 using below code:
MySecondFragment f2 = new MySecondFragment();
Bundle bundle = new Bundle();
FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
bundle.putInt("CurrentPosition", getAdapterPosition());
bundle.putIntArray("x", kolamTracingGameList.get(getAdapterPosition()).getX());
bundle.putIntArray("y", kolamTracingGameList.get(getAdapterPosition()).getY());
bundle.putInt("Level", (getAdapterPosition() + 1));
bundle.putString("GameType", "Kolam");
fragment.setArguments(bundle);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.replace(android.R.id.content, f2).addToBackStack(null).commit();
Problem is when I close Fragment
F2 and Fragment
F1 comes to foreground. Whole F1 is recreating(onViewCreated()
is called again). I don't want F1 to get recreated again when it comes to foreground.