Android startActivity exception
<p>I'm trying to start an activity from the <code>MainActivity</code> via the fab button. My code is below. The exception I get is:</p>

<pre><code>ActivityNotFoundException: Unable to find explicit activity class //packagename; have you declared this activity in your AndroidManifest.xml?
</code></pre>

<p>Although the exception is pointing me to my android manifest, I did add the activity there, although perhaps not correctly. Here is my code:</p>

<p>MainActivity.java</p>

<pre><code>import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

    /*
    *  OnLongClick - start listening via Listen class
    * */
    fab.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {

            Intent intent = new Intent(getApplicationContext(), Listen.class);

            Snackbar.make(view, "Bluetooth authentication is on", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
            startActivity(intent);
            return true;
        }
    });

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Bluetooth authentication turned off", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
</code></pre>

<p>Listen.java</p>

<pre><code>import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;

import java.util.List;
import java.util.UUID;

public class Listen extends Activity {

    private BeaconManager beaconManager;
    private Region region;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        beaconManager = new BeaconManager(this);

        region = new Region("ranged region",
                UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
    }


    @Override
    protected void onResume() {
        super.onResume();

        SystemRequirementsChecker.checkWithDefaultDialogs(this);

        beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
            @Override
            public void onEnteredRegion(Region region, List&lt;Beacon&gt; list) {
                showNotification(
                        "Welcome..",
                        "to the AccessLab!");
            }
            @Override
            public void onExitedRegion(Region region) {
                showNotification(
                        "You've left the lab..",
                        "Goodbye!");
            }
        });


        beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override
            public void onServiceReady() {
                beaconManager.startMonitoring(region);
            }
        });
    }



    public void showNotification(String title, String message) {
        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
                new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(this)
                .setSmallIcon(android.R.drawable.ic_dialog_info)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notification);
    }

}
</code></pre>

<p>AndroidManifest.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="accesscontrol2016"&gt;

&lt;application

    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"&gt;
    &lt;activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"&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=".Listen"
        android:label="@string/app_name"&gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.DEFAULT" /&gt;
            &lt;category android:name="accesscontrol2016.Listen" /&gt;
        &lt;/intent-filter&gt;
    &lt;/Activity&gt;
&lt;/application&gt;
</code></pre>

<p></p>

<p>As you can hopefully see I've added the <code>Listen</code> class to my activities in the Android Manifest. I'm not sure if I'm setting up my Intent properly, with <code>getApplicationContext()</code>. Any help much appreciated.</p>