Broadcast receiver fires twice

Viewed 78

I have an app that sends 5 different notifications each at a certain time in the day. I put a print log in the receiver. When the notification time is reached, it prints it twice. Is there any problem with that? Thanks in advance.

EDIT: this is my code for the alarm

public void Alarm(int nID,int y,int Bh, int Bm) {
        Calendar wakeupcall = Calendar.getInstance();

        wakeupcall.setTimeInMillis(System.currentTimeMillis());
        SimpleDateFormat datte = new SimpleDateFormat("yyyy", Locale.US);
        d = new Date();
        int xy = Integer.parseInt(datte.format(d));

        String cv = getDate1(y);
        BM = Integer.parseInt(cv.substring(0, 2));
        BD = Integer.parseInt(cv.substring(3));

        int day = wakeupcall.get(Calendar.DAY_OF_YEAR) + y;

        wakeupcall.set(Calendar.YEAR, xy);
        wakeupcall.set(Calendar.MONTH, BM);
        wakeupcall.set(Calendar.DAY_OF_MONTH, BD);
        wakeupcall.set(Calendar.HOUR_OF_DAY, Bh);
        wakeupcall.set(Calendar.DAY_OF_YEAR, day);
        wakeupcall.set(Calendar.MINUTE, Bm);
        wakeupcall.set(Calendar.SECOND, 0);
        wakeupcall.set(Calendar.MILLISECOND, 0);


        Intent intenter = new Intent(getContext(), AlarmReceiver.class);
                intenter.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), nID, intenter, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) Objects.requireNonNull(Objects.requireNonNull(getActivity()).getSystemService(Context.ALARM_SERVICE));

        if (Calendar.getInstance().before(wakeupcall)) {
            am.setExact(AlarmManager.RTC_WAKEUP, wakeupcall.getTimeInMillis(), pendingIntent);
        } else {
            am.cancel(pendingIntent);
        }

    }
0 Answers
Related