Return transition not working correctly when using fragment shared transitions
<p>I have 2 fragments <code>ListMovieFragment</code> and <code>DetailMovieFragment</code>.</p>

<p>I have an interface in <code>ListMovieFragment</code> that is implemented in the <code>MainActivity</code>. I am using shared element transition ; when I click the image view in <code>ListMovieFragment</code> the <code>onMovieSelected</code> is called in the <code>MainActivity</code>.</p>

<p>Transitioning from the <code>ListMovieFragment</code> works.<br>
But when I click the <kbd>back</kbd> button, transitioning from the <code>DetailMovieFragment</code> to the ListMovieFragment fails to work.</p>

<p><a href="https://i.stack.imgur.com/jEBFq.gif"><img src="https://i.stack.imgur.com/jEBFq.gif" alt="gif of what is going wrong"></a></p>

<p>Here is the MainActivity. I think I have got an incorrect combination for setting the transitions on the fragments.</p>

<pre><code>public class MainActivity extends AppCompatActivity implements ListMovieFragment.MovieSelectedListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if(savedInstanceState == null) {
            ListMovieFragment listMovieFragment = new ListMovieFragment();

            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(R.id.activity_main, listMovieFragment, ListMovieFragment.TAG);
            fragmentTransaction.commit();
        }
    }

    @Override
    public void onMovieSelected(int movieId) {
        DetailMovieFragment detailMovieFragment =
                (DetailMovieFragment)getSupportFragmentManager().findFragmentByTag(DetailMovieFragment.TAG);
        /* Create a new DetailMovieFragment if not exits */
        if(detailMovieFragment == null) {
            detailMovieFragment = new DetailMovieFragment();
        }

        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
            /* Get the fragments that will be using the transition */
            ListMovieFragment listMovieFragment =
                    (ListMovieFragment)getSupportFragmentManager().findFragmentByTag(ListMovieFragment.TAG);
            if(listMovieFragment == null) {
                listMovieFragment = new ListMovieFragment();
            }

            /* Inflate the transition */
            Transition changeTransition = TransitionInflater
                    .from(MainActivity.this)
                    .inflateTransition(R.transition.change_image_transform);

            /* source fragment (ListMovieFragment) */
            listMovieFragment.setExitTransition(new Explode());
            listMovieFragment.setSharedElementReturnTransition(changeTransition);

            /* Destination fragment (DetailMovieFragment) */
            detailMovieFragment.setSharedElementEnterTransition(changeTransition);
            detailMovieFragment.setEnterTransition(new Explode());

            /* Get the shared imageview from the source fragment (MovieListFragment) */
            final ImageView ivSharedImage = (ImageView) findViewById(R.id.ivMoviePoster);

            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.activity_main, detailMovieFragment, DetailMovieFragment.TAG);
            fragmentTransaction.addToBackStack(DetailMovieFragment.TAG);
            fragmentTransaction.addSharedElement(ivSharedImage, getResources().getString(R.string.transition_poster_image));
            fragmentTransaction.commit();
        }
        else {
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.activity_main, detailMovieFragment, DetailMovieFragment.TAG);
            fragmentTransaction.addToBackStack(DetailMovieFragment.TAG);
            fragmentTransaction.commit();
        }
    }

    @Override
    public void onBackPressed() {
        if (getSupportFragmentManager().getBackStackEntryCount() &gt; 0) {
            getSupportFragmentManager().popBackStack();
        }
        else {
            super.onBackPressed();
        }
    }
}
</code></pre>

<p>My transition xml file:</p>

<pre><code>&lt;transitionSet&gt;
    &lt;changeBounds /&gt;
&lt;/transitionSet&gt;
</code></pre>

<p>fragment_list</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="18dp"
    android:paddingBottom="6dp"&gt;

    &lt;ImageView
        android:id="@+id/ivMoviePoster"
        android:layout_width="184dp"
        android:layout_height="276dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:transitionName="@string/transition_poster_image"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>fragment_detail</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="me.androidbox.fragmenttransitions.detail.DetailMovieFragment"&gt;

    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="The Movie App"
        android:textSize="28sp"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/holo_blue_dark"/&gt;

    &lt;ImageView
        android:id="@+id/ivMoviePoster"
        android:layout_width="92dp"
        android:layout_height="138dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="112dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:layout_gravity="end"
        android:transitionName="@string/transition_poster_image"/&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>activity_main</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="me.androidbox.fragmenttransitions.activity.MainActivity"&gt;
&lt;/FrameLayout&gt;
</code></pre>