title: Close opened activity, so main activity can update fragment without state loss in Android
body: <p>I currently have two activities, the first one which is called when the app is opened, <code>EventsActivity</code> , and the second one which comes from <code>EventsActivity</code> called <code>EventActivity</code>.   If <code>EventActivity</code> is opened during a notification, which I process through <code>EventsActivity</code> within an onIntent, there is a <code>state loss</code> error because <code>EventActivity</code> is open.   How can I close <code>EventActivity</code> before updating my fragment in <code>EventsActivity</code>.</p>
  
  <p><strong>Launch EventActivity from EventsActivity</strong></p>
  
  <pre><code>public void launchEvent() {
      Intent intent = new Intent(this, EventActivity.class);
      startActivity(intent);
  }
  </code></pre>
  
  <p><strong>Update View Based On Notification From EventsActivity (EventActivity Is Opened)</strong></p>
  
  <pre><code>@Override
      public void onNewIntent (Intent intent)
      {
  FragmentManager manager = getSupportFragmentManager();
              FragmentTransaction fragmentTransaction = manager.beginTransaction();
              fragmentTransaction.replace(R.id.content_frame, new MessageFragment());
          manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // &lt;!-- state loss exception
      fragmentTransaction.commit();
      }
  </code></pre>