How to restore fragment back stack with in an activity (After application is killed in background)
<p>In an Android app-</p>

<p>Say I am in an <code>Activity</code> - <em>MyActivity</em> which holds one <code>Fragment</code> at a time.</p>

<p>First I loaded <strong>Fragment A</strong> to it (With no tags I added it to back stack of the <code>FragmentManager</code>)</p>

<p>Then at some point I loaded <strong>Fragment B</strong> (Again with no tags I added it to back stack of the <code>FragmentManager</code>)</p>

<p>Then at some point i loaded <strong>Fragment C</strong> (Again with no tags I added it to back stack of the <code>FragmentManager</code>)</p>

<p>I am using <code>popBackStack()</code> to enable <em>back button</em> behavior so whenever I press back from <strong>Fragment C</strong> the flow is like:</p>

<p><strong>Fragment C</strong> -> <strong>Fragment B</strong> -> <strong>Fragment A</strong> -> <strong>Close <em>MyActivity</em>..</strong></p>

<p>Everything is perfect :-)</p>

<p>But if I am in <strong>Fragment C</strong> and the app gets <em>killed in background</em> (I used "do not keep activity flag" from Settings)</p>

<p>and <em>come back online</em> <strong>Fragment C</strong> is loaded in <em>MyActivity</em></p>

<p>but the <code>FragmentManager</code>'s back stack contains only <strong>Fragment C</strong>..</p>

<p>The Back button is messing it up</p>

<p><strong>Fragment C</strong> -> <strong>Close MyActivity..</strong></p>

<p>Why is it so? </p>

<p>How to properly restore <code>FragmentManager</code>'s back stack within an <code>Activity</code>?</p>