简体   繁体   中英

pending intent alarm manager can't called twice

I am writing code to call the push notifications twice. But it only works once.

As you can see I am calling it at different times. What should I do to allow both notifications to work?

Intent intent = new Intent(MainActivity.this,ReminderBroadcast.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
    PendingIntent pendingIntent2 = PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    AlarmManager alarmManager2 = (AlarmManager) getSystemService(ALARM_SERVICE);

    long timeAtButtonClick = System.currentTimeMillis();
    long tenSecondsInMillis = 1000 * 10;
    long nextInMillis = 1000 * 20;
    alarmManager.set(AlarmManager.RTC_WAKEUP,timeAtButtonClick +  tenSecondsInMillis, pendingIntent);
    alarmManager2.set(AlarmManager.RTC_WAKEUP,timeAtButtonClick +  nextInMillis, pendingIntent2);

You should declare different PendingIntent requestCode try this

    PendingIntent pendingIntent2 = PendingIntent.getBroadcast(MainActivity.this,1,intent,0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM