title: Intent.FLAG_ACTIVITY_CLEAR_TOP causes activity to pop-up even when application is on background?
body: <p>I'm using Android 2.2. I have an application which logouts (causing the application to return to the login page) after a certain period of inactivity. I am using <code>Intent.FLAG_ACTIVITY_CLEAR_TOP</code> for my <code>Intent</code>. However, I notice that when my application is on background and is inactive for a certain period of time, the login page suddenly pops-up and my application goes to foreground. I am expecting that the login page will remain to background. This does not happen when I am not using any flag for my intent. If I'm not using any flag for my Intent, the login page is quietly started on the background. But without using <code>Intent.FLAG_ACTIVITY_CLEAR_TOP</code>, I won't be able to clear my history stack.</p>
  
  <p>Why is this happening? How can I launch an activity on background quietly?</p>
  
  <p>Below is a snippet of my code:</p>
  
  <pre><code>@Override //Inside a class extending AsyncTask
  protected void onPostExecute(String result)
  {
      ((GlobalApplication)getApplicationContext()).setIsLogin(false); //user is not logged in anymore
      Intent intent = new Intent(this, LoginActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);
  }
  </code></pre>
  
  <p>Below is a snippet the code I made from Lars' suggestion:</p>
  
  <pre><code>@Override //Inside a class extending AsyncTask
  protected void onPostExecute(String result)
  {
      ((GlobalApplication)getApplicationContext()).setIsLogin(false); //user is not logged in anymore
      Intent intent = new Intent(this, LoginActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
      if(((GlobalApplication)getApplicationContext()).isOnBackground())
          ((GlobalApplication)getApplicationContext()).setPendingIntent(intent);
      else
          startActivity(intent);
  }
  
  @Override //overrides android.app.Activity. inside the current Activity
  protected void onResume()
  {
      super.onResume();
      Intent pendingIntent = ((GlobalApplication)getApplicationContext()).getPendingIntent();
      if(pendingIntent != null)
          startActivity(pendingIntent);
  }
  </code></pre>