title: Android broadcastreceiver creates new instances
body: <p>Well, I have a class extending broadcastreceiver which is listening for messages. Now whenever it receives a message I creates a new instance of my app. So when I am closing it I have to tap back button 2 times.</p>
  <pre><code>public class SMSReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {
      Bundle myBundle = intent.getExtras();
      SmsMessage [] messages = null;
      String strMessage = &quot;&quot;;
      String phoneNumber = &quot;&quot;;
  
      if (myBundle != null) {
          Object [] pdus = (Object[]) myBundle.get(&quot;pdus&quot;);
          messages = new SmsMessage[pdus.length];
  
          for (int i = 0; i &lt; messages.length; i++) {
              messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
              strMessage += &quot;SMS From: &quot; + messages[i].getOriginatingAddress();
              strMessage += &quot; : &quot;;
              strMessage += messages[i].getMessageBody();
              strMessage += &quot;\n&quot;;
              
              phoneNumber = messages[i].getDisplayOriginatingAddress();
          }
          
          if (phoneNumber.equals(&quot;T-Mobile&quot;)) {
              Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();
              abortBroadcast();
          }
  
      }
  }
  }
  </code></pre>