I am currently adding a new fragment to the backstack (On top of the current fragment):
val fragmentTransaction = fragmentManager?.beginTransaction()
fragmentTransaction?.add(R.id.cl_my_profile_edit, newFragment)?.addToBackStack(null)
fragmentTransaction?.commit()
Will this pause the current fragment in which this code is run?
If this does not pause the current fragment
will calling onPause()
as such:
val fragmentTransaction = fragmentManager?.beginTransaction()
fragmentTransaction?.add(R.id.cl_my_profile_edit, newFragment)?.addToBackStack(null)
fragmentTransaction?.commit()
onPause()
Pause the current fragment?
add()
does not affect any other fragment - as the name implies, it simply adds a new fragment, overlapping any existing fragments in the same container.
You can use replace()
to replace any existing fragment, causing the other fragment to be paused, stopped, and have its view removed from the view hierarchy. This would ensure that the fragments don't visually overlap.
You cannot safely call onPause()
or any other on__
method - those are called by the framework, not by you.