I\'m fairly new to Android development and now running in to weird behaviour.
addToBackstack
creates a snapshot of your fragments state. Which means when you press the back button, you are actually reverting to the last state that addToBackstack
was called on.
In your case, you add a Fragment. The back button would remove this added fragment. When you call replace, and add to backstack again, you now have two states on the backstack (1. when you had the first fragment added, 2. when you had no fragments added). If you the back button to remove the current fragment, the don't use addToBackstack. Only use addToBackstack when you want to preserve the state of fragments in a view.