Hello! A similar question was already from me, but I did not receive an answer that would solve my problem. Probably you should not write your code here, because most likely, I chose the wrong approach to solving the problem. Nevertheless, I will leave a link to my previous question: here is my question .

Tell me, please, how to implement the following task: There is a table in the database in which there are records. The columns in the table: [ID] [NAME] [DAY] [HOURS] [MINUTES]

There is also an Activit that you need to call at a specified time.

That is, you need to scan the table in the database, and on the basis of these data you need to install the Alarm-s that will trigger Activiti.

The contents of Activiti do not need to be changed (it will be changed already in onCreate () of the Activit itself).

The problem is that I do not understand how to put alarms in the plural. Again, by the link above, I showed my vision of the implementation of the task.

Thanks in advance for the answers, I really hope for your help, because without solving this task I can’t move on :(

    1 answer 1

    Try replacing this in your code:

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra("alarm message", "alarm message"); if (android.os.Build.VERSION.SDK_INT >= 19) { am.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender); } else { am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender); } PendingIntent sender = PendingIntent.getBroadcast(context, i, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    Just for different versions of android registration pendingIntent -a occurs in different ways. Plus, you always registered it with the number 192837, I replaced it with i , since this variable is used in the loop, and it will be unique, and each subsequent pendingIntent will not overwrite the previous one.

    If there is a need to delete all registered intents, then call this function:

     public static void clearAlarmReceiver(Context context, int intentsCount) { for (int i = 0; i < intentsCount; i++) { Intent intent = new Intent(context, CheckAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, i, intent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } 
    • Thank you, your code has earned. But now another problem has appeared: the alarm clocks work instantly. Apparently, due to the fact that some of them are set to the past tense. How to filter this? - Pasha Oleynik
    • one
      Before installing alarms, delete all previous code that I gave above. Well, or as an option in the broadcastReceiver-e itself, compare by date. But for this in intent.putExtra put the date alarma. - Android Android