6

I made a simple sample to prove that there is something wrong with ActivityOptions.makeSceneTransitionAnimation(activity).

I got 3 activities: A, B & C. Flow is simple: A -> B -> C

All activities share the same style:

<style name="TransitionsTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:windowEnterTransition">@transition/slide_in_from_bottom</item>
    <item name="android:windowExitTransition">@transition/slide_out_to_bottom</item>
</style>

Whenever I go: A -> B -> C -> B (back button) -> A (back button) last animation(A -> C) is not played.

It works fine when only doing A -> B -> A (back button)

Here is how I start activities:

fun start(activity: Activity) {
            val intent = Intent(activity, TransitionActivityA::class.java) //or B or C
            val transitionsOptions = ActivityOptions.makeSceneTransitionAnimation(activity)
            activity.startActivity(intent, transitionsOptions.toBundle())
        }

App demonstrating the issue: https://github.com/jkwiecien/AndroidCaseStudies/tree/transitions Use branch transitions

Is that an Android bug or am I doing something wrong?

Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157
  • Did you try to override Activity's `onBackPressed` with calling to `overridePendingTransition()` method? like in answers on this question: https://stackoverflow.com/questions/28512662/slide-out-animation-not-working-on-back-press-button/28512750 – Artem Viter Jun 07 '21 at 15:45
  • `A -> B -> C -> B (back button) -> A (back button)` - What does it mean? From `C` to `B` -> `back button` to `A` -> `back button` to (expected) `C` ??? OR from `C` -> `back button` to `B` -> `back buttton` to `A` ??? In any case, [this post](https://stackoverflow.com/questions/2232238/how-to-bring-an-activity-to-foreground-top-of-stack) might help you. – Darkman Jun 11 '21 at 04:50
  • seems to work fine on emulator (api 24 and api 27), is it specific to some Android APIs? – rahul.taicho Jun 11 '21 at 08:38
  • yes, It doesn't work on API 30 in my case, but works fine on 23 and 24. – Haris Jun 11 '21 at 08:42
  • Launchmode sometimes messes with Transitions, if you use anything other than the default one that might be the source of it – Merthan Erdem Jun 12 '21 at 22:22

1 Answers1

-1

It does not work, because ActivityB is "started" by ActivityC, while it did work for the transition to ActivityB, because ActivityC is started by it.

It seems that you have to override onBackPressed() and start ActivityA from ActivityB manually, using reversed ActivityOptions. The only way of doing that is calling overridePendingTransition() after finish().

Cactusroot
  • 1,019
  • 3
  • 16