title: One application with two independent activities
body: <p>I am developing simple application with only two activities. </p>
  
  <ul>
  <li>Activity C configures application</li>
  <li>Activity A for interaction with user when some event occur</li>
  </ul>
  
  <p>It is not possible for user to navigate from the one to  the other - this is why I call them independent activities. Further more activity A is being invoked only form event, there is no way for user to do it manually.</p>
  
  <p>Problem. Let's assume that application is properly configured. Some event occurs in the system, so application A is being shown to the user. The user interact with it and activity goes to background. Then the user decides to launch configuration activity C. Activity C is shown to the user. The user uses back button to "close" activity, but instead of android launcher or desktop the user is being shown activity A (taken from history). </p>
  
  <p>Similar scenario might happen the other way. C is being used by user, then taken to background. Some event shows activity A and user using back button goes to C instead of closing activity A.</p>
  
  <p>I have solved the problem, but the solution is pretty dirty. Is there any <strong>clean</strong> or <strong>standard</strong> way of solving such problem?</p>
  
  <p>Part of my solution includes what was suggested in one answer:</p>
  
  <p>snippet from AndroidManifest.xml:</p>
  
  <pre><code>&lt;activity
    android:name=".C"
    android:clearTaskOnLaunch="true"
    android:excludeFromRecents="false"
    android:launchMode="singleTask"
    ...
   &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:exported="false"
    android:name=".A"
    android:excludeFromRecents="true"
    android:noHistory="true"
    android:launchMode="singleInstance"
    android:clearTaskOnLaunch="true"
    ....
  &gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>snippet from activity A:</p>
  
  <pre><code>public boolean onKeyUp(final int p_keyCode, final KeyEvent p_event) {
      switch(p_keyCode) {
          case KeyEvent.KEYCODE_ENDCALL:
          case KeyEvent.KEYCODE_HOME:
          case KeyEvent.KEYCODE_BACK:
          case KeyEvent.KEYCODE_MUTE:
          case KeyEvent.KEYCODE_POWER:
              this.finish();
              break;
          ....
      }
      return super.onKeyUp(p_keyCode, p_event);
  }
  </code></pre>
  
  <p>snipped from event handler:</p>
  
  <pre><code>public class H extends BroadcastReceiver {
  ...
    Intent intent = new Intent(p_context, A.class);
    intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    p_context.startActivity(intent);
  ...
  }
  </code></pre>
  
  <p>It works for my application. However I want application (activity C) to appear in <em>Recent</em> application. But once activity A is invoked application is removed from <em>Recent</em>.</p>