How to Start an activity on Receiving a PATICULAR sms from Broadcast Receiver class
<p>I am trying to start an activity from Broadcast Receiver class.
This is MainActivity.java</p>

<pre><code>package com.wissen.sms;

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

public class MainActivity 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>This is the SMSReceiver.java</p>

<pre><code>package com.wissen.sms.receiver;

import com.wissen.sms.Nwact;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

/**
 * The class is called when SMS is received.
 */
public class SMSReceiver extends BroadcastReceiver {


    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();

        Object messages[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[messages.length];
        for (int n = 0; n &lt; messages.length; n++) {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        }

        //show first message
        Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
        toast.show();

        //and then start an activity

        Intent i = new Intent(context,Nwact.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i); 
    }
}
</code></pre>

<p>This is the Manifest file :-</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.wissen.sms"
      android:versionCode="1"
      android:versionName="1.0.0"&gt;
      &lt;uses-sdk android:minSdkVersion="7" /&gt;

    &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
        &lt;activity android:name=".MainActivity"
                  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;activity android:name=".newact"&gt;&lt;/activity&gt;

    &lt;receiver android:name=".receiver.SMSReceiver" android:enabled="true"&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;/manifest&gt;
</code></pre>

<p>But when i Run i am getting the error in log file :-</p>

<pre><code>08-31 10:44:38.011: ERROR/AndroidRuntime(749): Uncaught handler: thread main exiting due to uncaught exception
08-31 10:44:38.031: ERROR/AndroidRuntime(749): java.lang.RuntimeException: Unable to start receiver com.wissen.sms.receiver.SMSReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wissen.sms/com.wissen.sms.Nwact}; have you declared this activity in your AndroidManifest.xml?
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2646)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ActivityThread.access$3100(ActivityThread.java:119)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.os.Looper.loop(Looper.java:123)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ActivityThread.main(ActivityThread.java:4363)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at java.lang.reflect.Method.invokeNative(Native Method)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at java.lang.reflect.Method.invoke(Method.java:521)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at dalvik.system.NativeStart.main(Native Method)
08-31 10:44:38.031: ERROR/AndroidRuntime(749): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wissen.sms/com.wissen.sms.Nwact}; have you declared this activity in your AndroidManifest.xml?
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ApplicationContext.startActivity(ApplicationContext.java:555)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at com.wissen.sms.receiver.SMSReceiver.onReceive(SMSReceiver.java:40)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2637)
08-31 10:44:38.031: ERROR/AndroidRuntime(749):     ... 10 more
</code></pre>

<p>Please specify where the problem is occuring.</p>
