title: Android: Stop new activity bringing app into foreground
body: <p>I posted a question yesterday as I have some specific requirements that seem to be quite difficult to achieve with android.</p>
  
  <p>I am working on an app that shows sensitive data and a requirement is that whenever another app gets focus or the app goes into the background because the home button was pressed the app should navigate to the login page. </p>
  
  <p>The app should also go to the login page when the 'all open apps' (not sure of name) button is pressed, as this should not show a screen shot of the current open activity but should show the login activity.</p>
  
  <p>I have been playing around with variations of the code below:</p>
  
  <pre><code>@Override
  public void onTrimMemory(int level) {
      super.onTrimMemory(level);
  
      if(level &gt;= TRIM_MEMORY_UI_HIDDEN &amp;&amp; ((!isInputtingPIN &amp;&amp; !isLoggedIn) || isLoggedIn)) {
  
          Log.d("AppGlobalData:", "*************** APP WINDOW IS BEING OBSCURED ***************");
          Intent login = new Intent(this.currentContext, AppEntryPoint.class);
          startActivity(login);
      }
  }
  </code></pre>
  
  <p>This works but the problem is that when the home button is pressed, the app goes into the background, but this firing of the new intent pulls the app back into the foreground. This also happens in the 'all apps' view.</p>
  
  <p>If I defer this intent firing until the app comes back into the foreground this is fine but the app does not move to the login page until it comes back to focus, that means if the app was on a page showing sensitive data and the all apps button is pressed the view of the app shows sensitive data.</p>
  
  <p>This was achieved in IOS by simply implementing a single method...</p>
  
  <p>Can anybody tell me how I can get the intent to change the activity but keep the app in the background? </p>