title: Android restore activity stack from notification exactly like the history selection does
body: <p>I have an application in which I keep all my activities with launchMode="singleTask". I like this better that doing flags soup ( mixing combinations to obtain the desired effect ), and base on receiving onNewIntent calls.</p>
  
  <p>However I have the following problem.</p>
  
  <p>If I launch the application, then R activity is started ( has launcher, Roster activity ).</p>
  
  <p>Then I launch activity S.</p>
  
  <p>(1) If I press the home button and I put the application to background, and then I press the history button ( the button from the rightest on Nexus 4, I think it's called like this ) I will be shown the S activity in the same state I left it after I pressed the home button.</p>
  
  <p>(2) However, If I press the home button and I put the application to background,and then I click on a notification to launch my application, then R activity is launched and the onNewIntent is called for it.</p>
  
  <p>Basically I would like the same behavior in the second case also. I am launching the application like this when clicking the notification:</p>
  
  <pre><code>   Intent rosterIntent = new Intent(this, RosterActivity.class);
     rosterIntent.addCategory(Intent.CATEGORY_DEFAULT);
     rosterIntent.setAction(Intent.ACTION_MAIN);
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 2,
     rosterIntent, 0);
  </code></pre>
  
  <p>It would seem this would be enough to relaunch the application in the same state I left it in, but it doesn't work. Maybe it's related that I have all my activities singleTask...</p>
  
  <p>Can someone tell me, please, If I need to add more flags to my intent, or the pending intent to obtain what I want?</p>
  
  <p>Regards,</p>
  
  <p>NOTE: it seems that clicking the launcher icon after the application is in the background has the same behavior like (2), so just selecting from history (1) is the behaviour that I want.</p>