Search code examples
androidbroadcastreceiveralarmmanager

Schedule Message sending through AlarmManager class.At The Second time my AlarlManager get overwrite


Hi everyone making an app for auto reply and i have set some delay in message sending on Broadcast of missed call through AlarmManager class.

It get override if i got the two missed calls symulteneosely.how i can fix it plese help.

here is my alarmManager on missed call broadcast

private void sendSMSWithDelay(String number, String responseMessage,
            int delayInResponce) {

        Intent intent = new Intent(Global.getMyApplicationContext(),
                MyCallBroadcastReceiver.class);
        // Intent i = new Intent(MessageService.this,
        // ViewMessageActivity.class);
        intent.putExtra("number", number);
        intent.putExtra("message", responseMessage);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                Global.getMyApplicationContext(), 234324243, intent, 0);
        AlarmManager alarmManager = (AlarmManager) Global
                .getMyApplicationContext().getSystemService(
                        Global.getMyApplicationContext().ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                + (delayInResponce * 60 * 1000), pendingIntent);

    }  

Solution

  • try this:

    private void sendSMSWithDelay(String number, String responseMessage,
                int delayInResponce) {
    
            Intent intent = new Intent(Global.getMyApplicationContext(),
                    MyCallBroadcastReceiver.class);
            // Intent i = new Intent(MessageService.this,
            // ViewMessageActivity.class);
            intent.putExtra("number", number);
            intent.putExtra("message", responseMessage);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(
                    Global.getMyApplicationContext(), new Random().nextLong(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager alarmManager = (AlarmManager) Global
                    .getMyApplicationContext().getSystemService(
                            Global.getMyApplicationContext().ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + (delayInResponce * 60 * 1000), pendingIntent);
    
        }