title: How to create BroadcastReceiver without Activity
body: <p>I would like to create a application that would respond to receiving SMS messages and display a dialog. How can I register the receiver in the manifest without defining within an activity?</p>
  
  <p>I tried to keep the receiver/intent-filter tags in the manifest out of the activity tag but the emulator will not install the apk since there is no launch activity. Keeping the BroadcastReceiver as the main activity results in an "Unable to instantiate activity" error in the Logcat.</p>
  
  <p>Any help?</p>
  
  <p>Thanks,
  Sunny</p>
  
  <p><strong>Receiver class</strong></p>
  
  <pre><code>public class SMSReceiver extends BroadcastReceiver {
  
   // onCreat is invoked when an sms message is received.
   // Message is attached to Intent via Bundle, stored in an Object
   // array in the PDU format.
   public void onReceive(Context context, Intent intent) {
    // get the SMS message passed in from Bundle
    Bundle bundle = intent.getExtras();        
      String bodyText = "";            
      String from = "";
      if (bundle != null) {
          //Retrieve sms message within Object array
          Object[] pdus = (Object[]) bundle.get("pdus");
          SmsMessage[] msgs = new SmsMessage[pdus.length];            
  
          for (int i=0; i &lt; msgs.length; i++)
           msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
  
          for (SmsMessage message: msgs) {
           bodyText = message.getMessageBody();
           from = "Message from " + message.getOriginatingAddress() + ": ";
          }
          // Display message in pop up
          Toast.makeText(context, from + bodyText, Toast.LENGTH_SHORT).show();
      }                  
   }
  }
  </code></pre>
  
  <p><strong>Manifest</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="home.splttingatms.SMSReceiver" android:versionCode="1" android:versionName="1.0"&gt;
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".SMSReceiver"
                    android:label="@string/app_name"&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;receiver android:name=".SMSReceiver"&gt;
     &lt;intent-filter&gt;
      &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
     &lt;/intent-filter&gt;
    &lt;/receiver&gt;
   &lt;/application&gt;
  
      &lt;uses-sdk android:minSdkVersion="7" /&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt;
  
  &lt;/manifest&gt; 
  </code></pre>