Junior — Middle
When transitioning between fragments, which class's method add is called?
sobes.tech AI
Answer from AI
In Android, when transitioning between fragments, the add method is called on a FragmentTransaction object.
The process usually looks like this:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.container, newFragment);
transaction.commit();
Here:
getSupportFragmentManager()returns the fragment manager,beginTransaction()creates a new transaction,add()adds a new fragment to the specified container,commit()applies the changes.
Thus, the add method is called on an instance of FragmentTransaction, which manages fragment operations.