What is the difference between enter/exit and popEnter/popExit animations? What is the difference between enter/exit and popEnter/popExit animations? android android

What is the difference between enter/exit and popEnter/popExit animations?


Let's start simple case:

Replace Fragment A with Fragment B (your second code snippet)

  • Fragment B runs enter animation
  • Fragment A runs exit animation

Press back button and undo the replace operation

  • Fragment B runs popExit animation
  • Fragment A runs popEnter animation

Now to answer your question.

You don't say if the container already has a fragment or not. Let's consider both cases:

  1. Container already had a fragment (let's call it Fragment 0) when the first operation to replace with Fragment A was called. When popping the entire stack:

    • Fragment B runs popExit animation (set in second snippet)
    • Fragment 0 runs popEnter animation (set in first snippet)
  2. Container was empty so replacing with Fragment A was essentially an add operation. When popping entire stack:

    • Fragment B runs popExit animation (set in second snippet)
    • No popEnter animation runs since container is now empty