0

I'm tring to make an action bar back button leads to different locations depends on which fragment of layout is visible. I want to make it always back to previous activity despite one case, when going back from one fragment must be proceded by another fragment with info about screen rotation. I tried simple if statement but even when RiderArenaFragment is visible, it goes back to home activity.

    override fun onActionBarButtonClicked(@IdRes id: Int) {
    when (id) {
        R.id.ab_back_btn -> {
            if(RiderArenaFragment().isVisible) setFragment(RiderArenaInfoFragment())
            else finish()
        }

    }
}
  • Found partial answer: https://stackoverflow.com/questions/9294603/how-do-i-get-the-currently-displayed-fragment , mixed with the code I wrote and it works correctly. – Formosa96 Jun 29 '21 at 12:31

0 Answers0