9

I have a litle problem.

I have a fragment A with a list and an activity B with also a list. Now A and B have an image in common, so I set up an shared element transition and it works on the way from A to B.

But I don't want to have the reverse transition if I press the back button. So I don't call in B supportFinishAfterTransition instead of finish. But now there is some ugly animation:

B disappears normally except the image. The image stays in foreground until A is visible in the background and then disappears.

How can I prevent this? I want the normal behavior like if I would call finish or onBackPressed.

Greets

lampenlampen
  • 947
  • 6
  • 21

2 Answers2

8

I found a solution.

I have played around a bit and if you override onBackPressed() and call finish() instead of super.onBackPressed(), It works.

lampenlampen
  • 947
  • 6
  • 21
  • supportLib 27.1.1, i have to use `finish()` to disable shared elements transition on return and reenter to A – hedzr Jul 26 '18 at 04:06
  • Hey, see my answer. Much cleaner to override finishAfterTransition() – guy_m Aug 29 '19 at 09:52
6

just stumbled upon this problem and there's a cleaner solution..

Just override finishAfterTransition(). You should have a boolean in your base class maybe, so it will look like this:

final override fun finishAfterTransition() {
    if (myShouldAllowReverseTransitionsBoolean) {
        super.finishAfterTransition()
    } else {
        super.finish()
    }
}
guy_m
  • 3,110
  • 2
  • 19
  • 33