Shared element activity transition on android 5 Shared element activity transition on android 5 android android

Shared element activity transition on android 5


I encounter the same issue, and notice the crash happens if the original shared element is no longer visible on the previous screen when you go back (probably it is the last element on screen in portrait, but once switched to landscape it's no longer visible), and thus the transition has nowhere to put back the shared element.

My workaround is to remove the return transition (in the 2nd activity) if the screen has been rotated before going back, but I'm sure there must be a better way to handle this:

@Overridepublic void onConfigurationChanged(Configuration newConfig) {    super.onConfigurationChanged(newConfig);    mOrientationChanged = !mOrientationChanged;}@Overridepublic void supportFinishAfterTransition() {    if (mOrientationChanged) {        /**         * if orientation changed, finishing activity with shared element         * transition may cause NPE if the original element is not visible in the returned         * activity due to new orientation, we just finish without transition here         */        finish();    } else {        super.supportFinishAfterTransition();    }}


If you're using Proguard then try adding this into your rules file. I had the same issue and it appears to work?

-keep public class android.app.ActivityTransitionCoordinator


Try removing any merge xml tags that you might have on the final activity's view. I have noticed that transitioning to a view, that contains a merge tag, in which the transitioning element is a direct child of the merge tag, will cause this error, but should I replace the merge tag with a different container like CardView, the animation works just fine. Also make sure that there is a 1:1 relationship between the transitionNames in the views.

UPDATE:I experienced this issue once more when doing an activity transition, clicking the back button to return to the initial activity, and then trying the transition again. I was accessing the direct parent of the 'transition component', (A RelativeLayout) by id, with a findViewById() call, and then calling removeAllViews(). I ended up changing the code to call 'removeAllViews()' on a greater ancestor than the parent, also removed a tag from the element that was to take the place of the 'transition component' after page load. This alleviated my issue.