Sending two notifications – specified at different time but shows up together

I need to create an application to send notifications at specific time. I’ve created what is presented below but I have a small problem.

In this case I want to set two notifications at diffrent time. E.g. first one at 12:18 and second one at 12:20.

The problem is that I do get these notifications together at 12:18 and what is surprising I get also together at 12.22 (two minutes later than it should appear). Which is really weird.

What should I change to get only one notification at specific time and the other one at different time.

This is how my application look like

This is my MainActivity.java

public class MainActivity extends AppCompatActivity
            implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener  {

    Button save1, btnTimePicker1, save2, btnTimePicker2;
    EditText txtTime1, txtTime2;
    public int mHour, mMinute;

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

        txtTime1 =(EditText)findViewById(R.id.in_time1);
        btnTimePicker1 = (Button)findViewById(R.id.btn_time1);
        save1 = (Button)findViewById(R.id.save1);
        btnTimePicker1.setOnClickListener(this);

        txtTime2 = (EditText)findViewById(R.id.in_time2);
        btnTimePicker2 = (Button)findViewById(R.id.btn_time2);
        save2 = (Button)findViewById(R.id.save2);
        btnTimePicker2.setOnClickListener(this);

        test1();
        test2();
    }

    public void test1() {
        save1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, mHour);
                calendar.set(Calendar.MINUTE, mMinute);
                calendar.set(Calendar.SECOND, 0);
                Log.i("mHour: ", String.valueOf(mHour));
                Log.i("mMinute: ", String.valueOf(mMinute));

                Intent intent0 = new Intent(MainActivity.this, MyReceiver.class);

                PendingIntent pendingIntent0 = PendingIntent.getBroadcast(
                        MainActivity.this, 123, intent0,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                AlarmManager am = (AlarmManager) MainActivity.this
                        .getSystemService(MainActivity.this.ALARM_SERVICE);
                am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                        AlarmManager.INTERVAL_DAY, pendingIntent0);
            }
        });
    }

    public void test2() {
        save2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, mHour);
                calendar.set(Calendar.MINUTE, mMinute);
                calendar.set(Calendar.SECOND, 0);
                Log.i("mHour: ", String.valueOf(mHour));
                Log.i("mMinute: ", String.valueOf(mMinute));

                Intent intent1 = new Intent(MainActivity.this, MyReceiver.class);

                PendingIntent pendingIntent1 = PendingIntent.getBroadcast(
                        MainActivity.this, 124, intent1,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                AlarmManager am = (AlarmManager) MainActivity.this
                        .getSystemService(MainActivity.this.ALARM_SERVICE);
                am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                        AlarmManager.INTERVAL_DAY, pendingIntent1);
            }
        });
    }

    @Override
    public void onClick(View v) {

        // Get Current Time
        final Calendar c = Calendar.getInstance();
        mHour = c.get(Calendar.HOUR_OF_DAY);
        mMinute = c.get(Calendar.MINUTE);

        switch(v.getId()) {
            case R.id.btn_time1:
                // Launch Time Picker Dialog
                TimePickerDialog timePickerDialog1 = new TimePickerDialog(this,
                        new TimePickerDialog.OnTimeSetListener() {

                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                txtTime1.setText(hourOfDay + ":" + minute);
                                mHour = hourOfDay;
                                mMinute = minute;
                            }
                        }, mHour, mMinute, false);
                timePickerDialog1.show();
                break;
            case R.id.btn_time2:
                // Launch Time Picker Dialog
                TimePickerDialog timePickerDialog2 = new TimePickerDialog(this,
                        new TimePickerDialog.OnTimeSetListener() {

                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                txtTime2.setText(hourOfDay + ":" + minute);
                                mHour = hourOfDay;
                                mMinute = minute;
                            }
                        }, mHour, mMinute, false);
                timePickerDialog2.show();
                break;
        }
    }

This is my MyReceiver.java

public class MyReceiver extends BroadcastReceiver{

    final int  NOTIFICATION_ID = 123;
    final int  NOTIFICATION_ID1 = 124;
    @Override
    public void onReceive(Context context, Intent intent) {

        CharSequence fromFirst = "test1";
        CharSequence fromSecond = "test2";
        CharSequence massageFirst = "test1";
        CharSequence massageSecond = "test2";

        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, NextActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);


        NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
                context).setSmallIcon(R.drawable.icon)
                .setContentTitle(fromFirst)
                .setContentText(massageFirst).setSound(alarmSound)
                .setAutoCancel(true).setWhen(when)
                .setContentIntent(pendingIntent)
                .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        notificationManager.notify(NOTIFICATION_ID, mNotifyBuilder.build());

        NotificationCompat.Builder mNotifyBuilder1 = new NotificationCompat.Builder(
                context).setSmallIcon(R.drawable.icon)
                .setContentTitle(fromSecond)
                .setContentText(massageSecond).setSound(alarmSound)
                .setAutoCancel(true).setWhen(when)
                .setContentIntent(pendingIntent)
                .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        notificationManager.notify(NOTIFICATION_ID1, mNotifyBuilder1.build());
    }
}

This is my manifest.xml

<receiver
    android:name=".MyReceiver" />

This is my content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.test.notification.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

    <EditText
        android:layout_width="145dp"
        android:layout_height="wrap_content"
        android:id="@+id/in_time1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SELECT TIME"
        android:id="@+id/btn_time1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SET"
        android:id="@+id/save1" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <EditText
            android:layout_width="145dp"
            android:layout_height="wrap_content"
            android:id="@+id/in_time2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SELECT TIME"
            android:id="@+id/btn_time2" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SET"
            android:id="@+id/save2" />
    </TableRow>

</TableLayout >