AlarmManager is not working in Android
<p>I'm following a tutorial on AlarmManager. I've run the tutorial's code in the emulator but the alarm does not go off.
In addition, the tutorial makes use of clone in the first java class for Calendar, why does it clone here?</p>

<p>Any help would be greatly appreciated.</p>

<p>Here is the code:</p>

<p>AndroidTimeActivity.java</p>

<pre><code>public class AndroidTimeActivity extends Activity {

TimePicker myTimePicker;
Button buttonstartSetDialog;
TextView textAlarmPrompt;

TimePickerDialog timePickerDialog;

final static int RQS_1 = 1;

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

    textAlarmPrompt = (TextView)findViewById(R.id.alarmprompt);

    buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
    buttonstartSetDialog.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View v) {
    textAlarmPrompt.setText("");
    openTimePickerDialog(false);

        }
    });

}


private void openTimePickerDialog(boolean is24r){
    Calendar calendar = Calendar.getInstance();

    timePickerDialog = new TimePickerDialog(
    AndroidTimeActivity.this,
    onTimeSetListener,
    calendar.get(Calendar.HOUR_OF_DAY),
    calendar.get(Calendar.MINUTE),
    is24r);
    timePickerDialog.setTitle("Set Alarm Time");

    timePickerDialog.show();

}

OnTimeSetListener onTimeSetListener
    = new OnTimeSetListener(){

    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

        Calendar calNow = Calendar.getInstance();
        Calendar calSet = (Calendar) calNow.clone();

        calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
        calSet.set(Calendar.MINUTE, minute);
        calSet.set(Calendar.SECOND, 0);
        calSet.set(Calendar.MILLISECOND, 0);

        if(calSet.compareTo(calNow) &lt;= 0){
        //Today Set time passed, count to tomorrow
        calSet.add(Calendar.DATE, 1);
        }

        setAlarm(calSet);
    }
};

private void setAlarm(Calendar targetCal){

    textAlarmPrompt.setText(
    "\n\n***\n"
    + "Alarm is set@ " + targetCal.getTime() + "\n"
    + "***\n");

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);

}

}
</code></pre>

<p>AlarmReceiver.java</p>

<pre><code>public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context arg0, Intent arg1) {
Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();
}
}
</code></pre>

<p>AndroidManifest.xml</p>

<pre><code>&lt;uses-permission android:name="com.android.alarm.permission.SET_ALARM" /&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=".AndroidTimeActivity"
        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;Receiver
        android:name=".AlarmReciever"
        android:label="@string/title_activity_alarm_reciever"
        android:theme="@style/AppTheme.NoActionBar"&gt;
    &lt;/Receiver&gt;
&lt;/application&gt;
</code></pre>

<p></p>