Android AlarmManager仅在调试模式下运行

时间:2018-09-26 12:17:57

标签: java android alarmmanager

我每天发送一次通知,并通过在setAlarm()方法中设置小时和分钟来对其进行测试:

public void setAlarm() {

        Intent serviceIntent = new Intent(this, NotificationService.class);
        PendingIntent pi = PendingIntent.getService(this, 131313, serviceIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Calendar today = Calendar.getInstance();
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.set(Calendar.HOUR_OF_DAY, 22);
        tomorrow.set(Calendar.MINUTE, 11);
        tomorrow.set(Calendar.SECOND, 0);
        if(today.compareTo(tomorrow) > 0)
            tomorrow.add(DATE, 1);
        am.set(AlarmManager.RTC_WAKEUP, tomorrow.getTimeInMillis(), pi);
        Log.v(TAG, "Alarm set");
    }

我要努力理解的是,为什么只有在调试应用程序时在方法内设置断点时,警报才起作用。如果我不在调试中,则通知不会显示。我想念什么吗?

0 个答案:

没有答案