0

因此,我试图每天早晨在大约早上10点向用户发送通知。用户可以选择取消每日通知。在android中使用闹钟管理器面对通知问题

我正面临一些问题。我在上午10点发出通知。我收到了。但是,它会在几秒钟或几分钟后抛出另一个通知。 我试图在单独的可运行线程中设置此通知。我能够成功实施取消选项,但我面临着这个多重通知问题。在这里,我安装的部分代码:

class Signup implements Runnable { 

    @Override 
    public void run() { 
     Calendar updateTime = Calendar.getInstance(); 
     updateTime.set(Calendar.HOUR_OF_DAY, 10); 
     updateTime.set(Calendar.MINUTE, 03); 
     updateTime.set(Calendar.SECOND,10); 

     Intent notification = new Intent(MainActivity.this, Alert.class); 
     PendingIntent recurringNotification = PendingIntent.getBroadcast(MainActivity.this, 
       0, notification, PendingIntent.FLAG_CANCEL_CURRENT); 



     AlarmManager alarms = (AlarmManager) MainActivity.this.getSystemService(
       Context.ALARM_SERVICE); 
     alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringNotification); 
    } 
} 

接收机:

​​

回答

0

想通了,为什么有人扔一个随机的通知。

如果时间已过,它会在运行应用程序时发出通知。所以在这种情况下,您需要在闹钟时间添加一天,如果

当前时间>闹钟时间