title: State of calling activity after startActivityForResult and Home key is pressed
body: <p>I have a launcher Activity called <code>HomeActivity</code>.</p>
  
  <p>And a <code>LoginActivity</code> from where the user has to login to access the other screens.</p>
  
  <p><code>HomeActivity</code> is marked as <code>singleTask</code>.</p>
  
  <p>In HomeActivity's <code>onCreate()</code> method, I launch the <code>LoginActivity</code> if the user is not logged in.</p>
  
  <p>And in <code>LoginActivity</code>, I just call a <code>finish()</code>, to dismiss the <code>LoginActivity</code>, assuming that the <code>HomeActivity</code> is the next activity in the stack to be shown.</p>
  
  <p>This setup works for most of the cases, except one.</p>
  
  <ol>
  <li>User is not logged in.</li>
  <li>Launch app -> Launches <code>HomeActivity</code></li>
  <li>No login detected -> Launches <code>LoginActivity</code></li>
  <li>On <code>LoginActivity</code>, press home.</li>
  <li>Launch the app, and I see the <code>LoginActivity</code>.</li>
  <li>Do a login, and on success, <code>LoginActivity</code> is finished.</li>
  </ol>
  
  <p>Instead of seeing the <code>HomeActivity</code>, I see the HomeScreen. Is that expected? Am I doing anything wrong? </p>
  
  <p>I don't have the developer option <strong>"Don't keep activities"</strong> turned <strong>off</strong>. So, was wondering how the activity stack loses the <code>HomeActivity</code>, since I am expecting the <code>HomeActivity</code> to be the next Activity to come up after I finish the <code>LoginActivity</code>.</p>
  
  <p><strong>Cancel or Login methods in LoginActivity:</strong></p>
  
  <pre><code>public void doLogin(View v) {
          setResult(RESULT_OK);
          finish();
  }
  
  public void cancel(View v) {
         setResult(RESULT_CANCELED);
         finish();
  }
  </code></pre>
  
  <p><strong>Calling LoginActivity:</strong></p>
  
  <p>Called from <code>onCreate()</code> and <code>onNewIntent()</code>.</p>
  
  <p><strong>Why onNewIntent() is needed?</strong> So that, from anywhere else, I can just start the <code>HomeActivity</code>, and <code>onNewIntent()</code> would be called, in case of session expiry. All the other activities on top of <code>HomeActivity</code> would be removed, and <code>LoginActivity</code> should be shown.</p>
  
  <pre><code>protected void onCreated(Bundle savedInstance){
          if(!isLoggedIn()){
               startLoginActivity();
          }
  }
  
  protected void onNewIntent(Intent intent){
          if(!isLoggedIn()){
               startLoginActivity();
          }
  }
  
  private void startLoginActivity(){
          Intent intent = new Intent(this, LoginActivity.class);
          startActivityForResult(intent, 100);
  }
  </code></pre>
  
  <p><strong>On Activity Result of HomeActivity:</strong></p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(resultCode == RESULT_CANCELED){
                  finish();
          }
          super.onActivityResult(requestCode, resultCode, data);
  }
  </code></pre>
  
  <p><strong>The manifest file:</strong></p>
  
  <pre><code>&lt;activity android:launchMode="singleTask"
              android:name="com.example.checkact.HomeActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
  &lt;/activity&gt;
  &lt;activity android:name="com.example.checkact.LoginActivity"&gt;&lt;/activity&gt;
  </code></pre>
  
  <p><strong>Update:</strong> Using <code>singleTop</code> seems to work fine, but I have no idea why does it behave like this with <code>singleTask</code>.</p>