The layout of my Android tablet app consists of a list of items and a details view. When a list item is selected the associated content is displayed in the details view.

```none
+--------+-------------+ 
| Item 1 |             |
+--------+    Item     |
| Item 2 |   details   |
+--------+             |
| Item 3 |             |
+--------+-------------+

```

The details view is a `Fragment` which is programmatically inflated into a `FrameLayout` placeholder:

```
<FrameLayout
    android:id="@+id/detail_fragment_placeholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

```

Here is the `Fragment` operation:

```
getSupportFragmentManager()
    .beginTransaction()
    .replace(containerViewId, fragment, fragmentTag)
    .addToBackStack(backStackStateName)
    .commit();

```

Multiple instances `[Dx]` of the `DetailsFragment` are added to the backstack when the user selects one item after another.

```
                [D3]
        [D2]    [D2]
[D1] -> [D1] -> [D1]

```

Therefore, the user needs to press the *BACK* button multiple times to pop the instances from the backstack to empty the details view.

How can I replace an existing instance `[Dx]` of `DetailsFragment` on the backstack when the `fragmentTag` of the existing `fragment` matches the `fragmentTag` of a new `fragment`?

```
[D1] -> [D2] -> [D3]

```