How to clear fragmentManager back stack without poping fragments?
<p>Simple question but seems impossible to answer...
How to clear fragmentManager back stack without poping fragments?</p>

<p>I understand it like this:</p>

<p>Back stack entries = list of previosly saved transactions with addToBackStack command.
For example: "replace Fragment 1 with Fragment 2".</p>

<p>popBackStack = do last saved transatcion reverse.
For example: "replace Fragment 2 with Fragment 1".</p>

<p>Let's say i did first transaction: F1->F2 and added this transaction to back stack. When I press back button now the F2->F1 will happen.</p>

<p>OK...But..</p>

<p>I've changed my mind and I want to clear the back stack.
I want the user to work with F2 fragment but when he/she presses back button the Activity should close like the back stack is empty.</p>

<p>I need something like:</p>

<pre><code>for(int i=0;i&lt;getFragmentManager().getBackStackEntryCount();i++){
    getFragmentManager().getBackStackEntryAt(i).remove();
}
</code></pre>

<p><strong>EDITED</strong>
I've tried to ask simple question to complex situation and I get simple answer ;) 
Abhishek Patel's answer is very good but it is not what I was looking for. Still it's a good answer. </p>

<p><strong>Just to clarify:</strong>
Back stack in android is not fully editable list like:</p>

<ul>
<li>transaction 1  </li>
<li>transaction 2  </li>
<li>transaction 3</li>
<li>transaction 4</li>
</ul>

<p><em>We <strong>can't</strong> do "Remove transaction 3" to make:</em></p>

<ul>
<li>transaction 1  </li>
<li>transaction 2  </li>
<li>transaction 4</li>
</ul>

<p><em>We <strong>can't</strong> clear all backstack and keep last visible fragment alive.</em></p>

<p><em>We <strong>can</strong> delete backstacks records to certain position like:
"Remove everything to Transaction 2" to get:</em></p>

<ul>
<li>transaction 1</li>
<li>transaction 2</li>
</ul>

<p>On screen you'll see the efect of transaction 2.</p>

<p><strong>WHY DID I NEED THIS?</strong></p>

<p>I thought that I can make a Fragment which will be 'Main fragment'.This main fragment will use an Interface to tell whatever activity it is in that this boss fragment is shown now, and whatever happens before - is not important anymore.</p>

<p>(F)-Fragment, (A)-Activity</p>

<p>(F) - Hey dude. I'm the boss and I'm visible and attached to you. Please clear your backstack for me but keep my transaction which brought me here.</p>

<p>(A) - Sorry man...You should have told me before your transaction to clear my backstack so I can add your transaction on top of fresh new backstack.</p>