broadcastreceiver
<p>here i am trying to read the message and toast it i have seen various examples where there is a separate class that extends broadcastreceiver but they have not mentioned how to start this class(do we use startactivity() or somthing else). I have posted the code that i dowladed through a link from oriely's cookbook. I've tried to sms from ddms but i doesnt shows toast of message.Any help is appreciated as this is my first time with broadcastreceiver.</p>

<p><strong>invitationSMSreciever.java</strong></p>

<pre><code>    package com.SMS;


import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.sax.StartElementListener;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class invitationSMSreciever extends BroadcastReceiver {

    final String TAG = "BombDefusalApp";
    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        String message = "";
        if(bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];

            for(int i=0; i&lt;msgs.length;i++) {
                msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                   message = msgs[i].getMessageBody();
                Toast.makeText(context,message,Toast.LENGTH_SHORT).show();

                if (msgs[i].getMessageBody().equalsIgnoreCase("Invite")) {
                    //Intent myIntent = new Intent(MainMenu.this, com.bombdefusal.ReceivedSMSActivity.class);
                    Intent myIntent = new Intent();
                    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    myIntent.setAction("com.example.helloandroid.INVITE");
                    context.startActivity(myIntent);
                }
            }

        }

    }

}
</code></pre>

<p><strong>MainMenu</strong></p>

<pre><code>package com.SMS;

import com.SMS.R;

import android.app.Activity;
import android.os.Bundle;

public class MainMenu extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
</code></pre>

<p><strong>ReceivedSMSActivity</strong></p>

<pre><code>package com.SMS;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

import com.SMS.R;

public class ReceivedSMSActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startService(new Intent ("com.android.PLAY"));
        setContentView(R.layout.invite);
    }
    public boolean onKeyDown(int keyCode, KeyEvent service) {
        stopService(new Intent("com.bombdefusal.START_AUDIO_SERVICE"));
        finish();
        return true;
    }
}
</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="com.SMS" android:versionCode="1" android:versionName="1.0"&gt;
    &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt;
    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
        &lt;activity android:name=".MainMenu" android:label="@string/app_name"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="com.SMS" /&gt;
                &lt;category android:name="android.intent.category.DEFAULT" /&gt;
            &lt;/intent-filter&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:name="com.SMS.ReceivedSMSActivity"
                  android:label="@string/app_name"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="com.example.helloandroid.INVITE"/&gt;
                &lt;category android:name="android.intent.category.DEFAULT"/&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

        &lt;receiver android:name="com.SMS.invitationSMSreciever"
                  android:enabled="true"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.provider.Telephony.SMS_RECEIVED"/&gt;
                &lt;category android:name="android.intent.category.DEFAULT"/&gt;
            &lt;/intent-filter&gt;          
        &lt;/receiver&gt;

    &lt;/application&gt;


&lt;/manifest&gt; 
</code></pre>
