I am trying to make an android app in which one activity can have many fragments inside it.Therefore, when i start a particular activity and when its saved instance is null then i load fragment.This works fine.
class Activity : MainActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.activity_cart)
val frame = findViewById<ViewGroup>(R.id.frame_layout)
layoutInflater.inflate(R.layout.activity_fun, frame)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, FunFragment()).addToBackStack(null).commit()
}
savedInstanceState?.clear()
}
}
But main problem arises when i presses back button.It removes the fragment but it doesn't loads previous activity/fragment but it just shows a blank screen with white back when i presses back button inside Activity/FunFragment.How i can resolve this issue? When i am i Funfragment() then pressing back button should leads to previous activity