Почему доза уведомления увеличивается при установке времени уведомления?

Я использовал средство выбора времени, чтобы установить время уведомления пользователя. Я использовал диспетчер аварий и уведомлений.

Я вызвал метод setAlarm для clickListener кнопки, чтобы сохранить данные. Поэтому, когда этот метод setAlarm вызывается, Notification повышается в то же время, как и в то время, когда пользователь установил.

Я не хочу, чтобы он поднимался при сохранении данных.

Кто-нибудь может сказать, почему это происходит?

метод setAlarm

@SuppressLint("NewApi")
private void setAlarm(Calendar targetmCalen) {

    AlarmManager alarmMgr;
    PendingIntent alarmIntent;
    alarmMgr = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(getApplicationContext(), NotificationReceiver.class);
    alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
    Toast.makeText(getBaseContext(),
            "call alarmManager.setExact()",
            Toast.LENGTH_LONG).show();

    intent.putExtra("title",eventTitle);


    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, targetmCalen.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, alarmIntent);

    ComponentName receiver = new ComponentName(getApplicationContext(),NotificationReceiver.class);
    PackageManager pm = getApplicationContext().getPackageManager();

    pm.setComponentEnabledSetting(receiver,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

}

NotificationReceiver

public class NotificationReceiver  extends BroadcastReceiver {


    private static final int MY_NOTIFICATION_ID = 0;
    NotificationManager notificationManager;
    Notification myNotification;

    EventTableHelper db;

    @Override
    public void onReceive(Context context, Intent intent) {


        Toast.makeText(context, "Time is set", Toast.LENGTH_LONG).show();

        db = new EventTableHelper(context);

        List<EventData> testSavings = db.getAllEvents();

        for (EventData ts : testSavings) {
            String log = "from date:" + ts.getFromDate()
                    + " ,to date: " + ts.getToDate()
                    + " ,location: " + ts.getLocation()
                    + " ,title " + ts.getTitle();

            Date date = new Date();
            Date date1 = new Date();
            Log.d("Result: ", log);

            SimpleDateFormat df = new SimpleDateFormat("E MMM dd HH:mm:ss zzzz yyyy");
            SimpleDateFormat df2 = new SimpleDateFormat("HH:mm a");

            try {
                date = df.parse(ts.getFromDate());
                date1 = df.parse(ts.getToDate());
            } catch (ParseException ex) {

            }
            String timeFrom = df2.format(date);
            String startTime = String.valueOf(timeFrom);

            String timeTo = df2.format(date1);
            String endTime = String.valueOf(timeTo);


            String location = ts.getLocation();
            String title = ts.getTitle();


            Intent myIntent = new Intent(context, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(
                    context,
                    0,
                    myIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            if(location.equals(""))
            {
                String msg = "From : " + startTime + "\nTo : " + endTime;

                myNotification = new NotificationCompat.Builder(context)
                        .setContentTitle("Event : " + title)
                        .setContentText(msg)
                        .setWhen(System.currentTimeMillis())
                        .setContentIntent(pendingIntent)
                        .setAutoCancel(true)
                        .setSmallIcon(R.drawable.eventicon)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                        .setDefaults(Notification.DEFAULT_SOUND)
                        .build();

            }

            else
            {
                String msg = "From : " + startTime + "\nTo : " + endTime + "\nAt : " + location;
                myNotification = new NotificationCompat.Builder(context)
                        .setContentTitle("Event : " + title)
                        .setContentText(msg)
                        .setWhen(System.currentTimeMillis())
                        .setContentIntent(pendingIntent)
                        .setAutoCancel(true)
                        .setSmallIcon(R.drawable.eventicon)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                        .setDefaults(Notification.DEFAULT_SOUND)
                        .build();

            }

            Log.i("Notify", "Notification");
            notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(MY_NOTIFICATION_ID, myNotification);

        }
    }
}

РЕДАКТИРОВАТЬ:

Calendar object Passed in setAlarm method

     c.set(Calendar.HOUR_OF_DAY, hour);
            c.set(Calendar.MINUTE, minute);
            c.set(Calendar.SECOND,0);
            c.set(Calendar.MILLISECOND,0);
            c.set(Calendar.DATE, day);
            c.set(Calendar.DAY_OF_WEEK,2);
            notification = c.getTime();
            notificationTime = df.format(notification);
            Toast.makeText(getApplicationContext(),notificationTime,Toast.LENGTH_SHORT).show();

Спасибо..

Ответы на вопрос(0)

Ваш ответ на вопрос