Always launch activity X after resume from background and new launch - Android
<p>I need to implement the following:</p>

<p>When the app starts, activity A is shown (a login screen) that goes to activity B if login credentails are correct.</p>

<p>Activity B is a dasbhoard, that can start several other activities C,D .. (and thus remains active, the user should be able to go back to B if he/she is at C or D).</p>

<p>Now when the user presses the home button, and goes back to the app (ie. by pressing the home button for a long time), the app should show activity A again. It should not resume the activity (B,C,D) it was currently on.</p>

<p>In other words, the app should 'close' when it goes to the background (by launching another app or pressing the home button). However, this seems not so trivial in Android.</p>

<p>I have tried several strategies:</p>

<ul>
<li>use launchmode = singletask for activity A (app can still be resumed when long pressing home)</li>
<li>track the activity stack to see if app is going to the background on onPause (detection does not work flawlessly) and if resumed from background clear activity stack and start activity A again</li>
<li>use clearstack on Activity A and finishTaskOnTaskLaunch on all other activities </li>
<li>use nohistory (no going back to activity B)</li>
<li>use launchmode = singleinstance (actually dont want to go there)</li>
</ul>

<p>All seem to have their edge cases in which it doesnt work (ie. activity B is still resumed in some cases, activity B is closed when going back from activity C or D)</p>

<p>Any ideas? Am I perhaps overlooking something?</p>
