android - 多重通知--android

标签 android performance

我正在使用警报管理器显示多个本地通知。通知工作正常,但通知的顺序只有在我从通知栏中清除它后才会发生。序列没有发生。

未决 Intent 代码

Intent intent = new Intent(this, TimeAlarm.class);
        for(int i=0;i<milliSec.size();i++){     
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,intent, PendingIntent.FLAG_ONE_SHOT);
        am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),(milliSec.get(i)), pendingIntent);
        System.out.println("Calling Alaram...");

显示通知的代码

public void onReceive(Context context, Intent intent) {
     nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
     CharSequence from = "Sample Notification";
     CharSequence message = "Notification different milliseconds ...";
     PendingIntent contentIntent = PendingIntent.getActivity(context, 0,  new Intent(), 0);
     Notification notif = new Notification(R.drawable.ic_launcher, "Notification Test...", System.currentTimeMillis());
     notif.setLatestEventInfo(context, from, message, contentIntent);
     notif.flags= Notification.FLAG_AUTO_CANCEL;
     nm.notify(1, notif);
    }

如何在不从通知中清除现有消息的情况下执行多个通知序列。提前致谢

最佳答案

使用这行代码

nm.notify( System.currentTimeMillis(), notif);

您已将其设置为 1,因此每次它都会覆盖通知

关于android - 多重通知--android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18224235/

相关文章:

android - Firebase ML 套件给出 FirebaseMLException : Waiting for the text recognition model to be downloaded. 请稍候

php - 在 MYSQL 中查询或使用 PHP 逻辑更快

java - MongoDB 在负载下执行缓慢

python - 为什么对邻居进行平均的速度如此之慢?

c# - 将列表克隆到现有列表中、最小化内存重新分配的最有效方法?

java - 在第一次迭代中使用 ArrayList 的初始容量时出现一些回归

android - 无法将不同的 Drawables 设置为 recyclerview 项目

android - Cardslib 卡片的 LinearLayout wrap_content

java - 从 Parse 加载图像时出现 NullPointerException

android - 如何在虚拟键盘上的Android模拟器上打开剪贴板?