title: Android activity and fragment transition animation
body: <p>I have two activities, both of them will initial a fragment within its activity layout. However, I have trouble adding animation from activity A to activity B. The transition works just fine. Here is some code snippet. </p>
  
  <p>I've tried using overridePending, which basically does nothing. Also, I tried adding custom animation through .setCustomAnimations() in fragmentManager. However, I could only see the second animation slide in but not sliding out. And no animation at all for the first activity.</p>
  
  <p>Main Activity (Activity A):</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          if(savedInstanceState == null){
              getSupportFragmentManager()
                      .beginTransaction()
                      .add(R.id.fragment_container, new MainFragment())
                      .commit();
          }
      }
  
      public void gotToCommentActivityWithPostId(String postId){
          Intent intent = new Intent(this, CommentActivity.class);
          Bundle b = new Bundle();
          b.putString(CommentActivity.POST_ID_KEY, postId);
          intent.putExtras(b);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>Main Activity layout:</p>
  
  <pre><code>    &lt;android.support.constraint.ConstraintLayout 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="yaojungyang.testing.Screens.MainScreen.MainActivity"&gt;
  
  
      &lt;FrameLayout
          android:id="@+id/fragment_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;&lt;/FrameLayout&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Destination Activity(Activity B):</p>
  
  <pre><code>public class CommentActivity extends AppCompatActivity {
      public static final String POST_ID_KEY = "POST_ID_KEY";
  
      @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.comment_activity_layout);
          if(savedInstanceState == null){
              Bundle bundle = new Bundle();
              bundle.putString(POST_ID_KEY, getIntent().getStringExtra(POST_ID_KEY));
              Fragment fragment = new CommentFragment();
              fragment.setArguments(bundle);
              getSupportFragmentManager()
                      .beginTransaction()
                      .setCustomAnimations(R.anim.slide_from_right, R.anim.slide_to_right, R.anim.slide_to_right, R.anim.slide_to_right)
                      .add(R.id.fragment_container, fragment)
                      .commit();
          }
      }
  }
  </code></pre>
  
  <p>Destination Activity layout:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout 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="yaojungyang.testing.Screens.MainScreen.MainActivity"&gt;
  
  
      &lt;FrameLayout
          android:id="@+id/fragment_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>