title: MaterialContainerTransform transition is not Working on Return
body: <p>My MaterialContainerTransform transition is working from source -&gt; destination, but not the other way around. My situation is pretty standard -- I am attempting to provide a simple transition from a RecyclerView item (source Fragment) to a &quot;details&quot; Fragment (destination Fragment). The items within the RecyclerView are MaterialCardViews, each with an ImageView which is shared in the destination Fragment.</p>
  <p>Following these docs <a href="https://material.io/develop/android/theming/motion" rel="nofollow noreferrer">https://material.io/develop/android/theming/motion</a> it seems to be fairly straightforward, though the docs are written in Kotlin and I am using Java so maybe I am missing something? I dynamically set the ImageView transitionName in each RecyclerView item, and pass that to the destination Fragment which then copies the transitionName to its own ImageView. Through logging, I can confirm the shared transitionName matches in each fragment.</p>
  <p>The transition from source -&gt; destination works great, but when I hit the back button there is no transition back. This is strange because even the docs state:</p>
  <blockquote>
  <p>Fragments are able to define enter and return shared element transitions. When only an enter shared element transition is set, it will be re-used when the Fragment is popped (returns).</p>
  </blockquote>
  <p>Any ideas why the return transition (destination -&gt; source) is not functioning? Here is the relevant code:</p>
  <h2>RecyclerView Item (Source) **the ImageView is the shared element</h2>
  <pre><code>&lt;com.google.android.material.card.MaterialCardView
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:id=&quot;@+id/result_layout_card&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      app:cardCornerRadius=&quot;5dp&quot;
      app:cardElevation=&quot;4dp&quot;
      android:layout_margin=&quot;8dp&quot;
      android:clickable=&quot;true&quot;
      android:focusable=&quot;true&quot;
      android:checkable=&quot;true&quot;
      app:checkedIconTint=&quot;@color/checkedYellow&quot;
      &gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:orientation=&quot;vertical&quot;
          android:layout_gravity=&quot;center&quot;&gt;
  
  
          &lt;ImageView
              android:id=&quot;@+id/result_image_thumbnail&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:adjustViewBounds=&quot;true&quot;
              android:scaleType=&quot;fitCenter&quot;
              android:contentDescription=&quot;@string/thumbnail_content_description&quot;
              android:src=&quot;@drawable/corolla_preview&quot;
              /&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:padding=&quot;5dp&quot;
              android:orientation=&quot;vertical&quot;&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/result_text_title&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:text=&quot;2018 Toyota Corolla&quot;
                  style=&quot;@style/TextAppearance.MaterialComponents.Subtitle1&quot;
                  /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/result_text_stock&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:text=&quot;#626546&quot;
                  style=&quot;@style/TextAppearance.MaterialComponents.Body2&quot;
                  /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/result_text_price&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:text=&quot;$28,998&quot;
                  style=&quot;@style/TextAppearance.MaterialComponents.Overline&quot;
                  /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/com.google.android.material.card.MaterialCardView&gt;
  </code></pre>
  <h2>Detail Fragment (destination) ** again the ImageView is the shared element</h2>
  <pre><code>&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:layout_height=&quot;match_parent&quot;
      android:layout_width=&quot;match_parent&quot;
      &gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:orientation=&quot;vertical&quot;
          android:padding=&quot;8dp&quot;&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/detail_image_thumbnail&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;225dp&quot;
              android:contentDescription=&quot;@string/thumbnail_content_description&quot;/&gt;
          
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  <h2>RecyclerView Holder (source) ** the viewResults method is where I start the fragment transaction</h2>
  <pre><code>public class ResultsHolder extends RecyclerView.ViewHolder {
  
      private static final String TAG = ResultsHolder.class.getSimpleName();
      private final FragmentManager fragmentManager;
      private ResultModel resultModel;
  
      private final MaterialCardView cardView;
      private final ImageView thumbnail;
      private String searchId;
  
      private ResultsFragment resultsFragment;
      private int position;
      private View thumbnailView;
  
      public ResultsHolder(View itemView, FragmentManager fragmentManager,
                           String searchId, ResultsFragment resultsFragment) {
          super(itemView);
  
          cardView = itemView.findViewById(R.id.result_layout_card);
          thumbnail = itemView.findViewById(R.id.result_image_thumbnail);
  
          this.fragmentManager = fragmentManager;
          this.searchId = searchId;
  
          this.resultsFragment = resultsFragment;
  
      }
  
      public void bindResult(ResultModel result, int position) {
          resultModel = result;
  
          Picasso.get().load(result.getImageUrl()).into(thumbnail);
  
          cardView.setChecked(result.isChecked());
          cardView.setOnClickListener(cardViewClickListener);
  
          this.position = position;
          thumbnail.setTransitionName(result.getVin()); // transition name is unique for each recyclerview 
                                                        // item
  
      }
  
      private final View.OnClickListener cardViewClickListener = new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              viewDetails(resultModel, searchId);
          }
      };
  
  
      // This is the method where I start the destination fragment
      public void viewDetails(ResultModel result, String searchId) {
          Bundle args = new Bundle();
          args.putParcelable(&quot;RESULT&quot;, Parcels.wrap(result));
          args.putString(&quot;SEARCH_ID&quot;, searchId);
  
          DetailFragment fragment = new DetailFragment();
  
          // Destination fragment enter transition!
          fragment.setSharedElementEnterTransition(new MaterialContainerTransform());
          fragment.setArguments(args);
  
          fragmentManager
                  .beginTransaction()
                  .setReorderingAllowed(true)
                  .addSharedElement(thumbnail, thumbnail.getTransitionName()) // Shared element!
                  .replace(R.id.main_fragment_container,
                          fragment,
                          DetailFragment.class.getSimpleName())
                  .addToBackStack(null)
                  .commit();
      }
  </code></pre>
  <h2>Details Fragment (destination)</h2>
  <pre><code>public class DetailFragment extends Fragment {
  
      @SuppressWarnings(&quot;unused&quot;)
      private static final String TAG = &quot;DetailFragment&quot;;
      private ResultModel result;
      private String searchId;
  
      ImageView image;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getArguments() != null) {
  
              // Get result and search ID
              result = Parcels.unwrap(getArguments().getParcelable(&quot;RESULT&quot;));
              searchId = getArguments().getString(&quot;SEARCH_ID&quot;);
  
          }
  
      }
  
  
      private void instantiateUI(View v) {
          
          TextView vin = v.findViewById(R.id.tv_details_vin);
          vin.setText(result.getVin());
          
          image = v.findViewById(R.id.detail_image_thumbnail);
          Picasso.get().load(result.getImageUrl()).fit().into(image);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View v = inflater.inflate(R.layout.fragment_detail, container, false);
  
          // Set transitionName exactly same as the recyclerview item which was clicked
          v.findViewById(R.id.detail_image_thumbnail).setTransitionName(result.getVin());
          return v;
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          if (((AppCompatActivity) getActivity()) != null
                  &amp;&amp; ((AppCompatActivity) getActivity()).getSupportActionBar() != null) {
  
              Objects.requireNonNull(((AppCompatActivity) getActivity())
                      .getSupportActionBar()).setTitle(&quot;Details&quot;);
          }
  
          instantiateUI(view);
      }
  }
  </code></pre>