title: How to bring an Activity to foreground (or create if not existing)?
body: <p>I am intercepting sms messages with some information in them. Then in my SmsListener I'm creating notification to show in statusbar.
  Then, when user clicks on a notification I want</p>
  
  <ol>
  <li>Bring MainActivity to foreground (If such activity does not exist yet it should be created)</li>
  <li>Pass to it data from the sms</li>
  <li>Perform some ui changes basing on this data in this MainActivity</li>
  </ol>
  
  <p>My activity is defined as </p>
  
  <pre><code>    &lt;activity
          android:name=".MainActivity"
          android:screenOrientation="sensor"
          android:label="@string/app_name"
          android:launchMode="singleTask"/&gt;
  </code></pre>
  
  <p>Activity is launched as</p>
  
  <pre><code> Intent i = new Intent();
   i.setClass(context, MainActivity.class);
   i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   context.startActivity(i);
  </code></pre>
  
  <p>Also in my activity I have overridden method onNewActivity</p>
  
  <pre><code> @Override
   public void onNewIntent(Intent intent){
      super.onNewIntent(intent);
  
      // I have data from broadcast in intent variable passed to this activity
      processDataFromBroadcast(intent);
  }
  </code></pre>
  
  <p>It works fine if the MainActivity already exists but if MainActivity does not exist it is started however onNewIntent was not called</p>
  
  <p>Then I tried to invoke processDataFromBroadcast from onCreate: <code>processDataFromBroadcast(getIntent())</code>.
  First time data is passed correctly from my broadcast to the activity.
  However if MainActivity is sent to background and then again brought to foreground either onCreate or onNewIntent is called and processDataFromBroadcast is executed again with intent sent by broadcast and thus my MainActivity is updated with data from broadcast every-time the app is bringing to foreground - the latter is unwanted, how can I make my activity to forget this intent after first handling.
  <a href="http://www.box.net/shared/si6krushrv" rel="noreferrer">Here is sample application.</a></p>