1

First sorry for my english. I have a list of alarms and I need to wake up the application with a notification in a specific time. I only put one alarm at a time. I put an alarm with the set function, it works, then I put the next alarm in the broadcast but it doesn't wake up at time. Why? The milliseconds are diferent and correct but the alarm doesn't work.

public static void setNextAlarma(long milisegundos){
    Bundle extras = new Bundle();
    extras.putString("mensaje", "message");
    Intent i = new Intent(InfoApp.ALERT_MANAGER);
    i.putExtras(extras);

    PendingIntent pintent = PendingIntent.getBroadcast(InfoApp.miContexto, (int) milisegundos, i, 0);

    if (milisegundos != 0){
        InfoApp.miContexto.registerReceiver(AlertasBrCast, new IntentFilter(InfoApp.ALERT_MANAGER));

        AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE);

        alarm.set(AlarmManager.RTC_WAKEUP, milisegundos, pintent);

    }
    else{
        AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE);
        alarm.cancel(pintent);
    }
}

public final static BroadcastReceiver AlertasBrCast = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle extras = intent.getExtras();

            String mensaje = "";
            if (extras != null)
                mensaje = extras.getString("mensaje");

            generateNotification(context, mensaje, Calendario.class, null);

            updateAlarm();
        }
    };

    public void updateAlarm(){
// Consult the next alarm in the database 
long fechaNuevaMilli = (Utilidades.strToDate(nuevaFecha,
                    InfoApp.formatoSQL)).getTime();


            Utilidades.setNextAlarma(fechaNuevaMilli);
}

Thank you

user1852854
  • 199
  • 1
  • 1
  • 11

1 Answers1

0

alarm.set(AlarmManager.RTC_WAKEUP, milisegundos, pintent); will set the alarm once only user setRepeating function specify the delay interval

here is perfect solution

Alarm Manager Example

Community
  • 1
  • 1
Aashish Bhatnagar
  • 2,595
  • 2
  • 22
  • 37
  • I have a problem with this. It works but if the application is in background the alarm don't work. Where is the problem? Thank you! – user1852854 Jul 23 '13 at 08:35