Hello, I have created a notification system which every so often I will check if there are notes to show them and that does it through an Alarmmanager that stays in the background cache running. That makes it perfect, but the problem is that when I want it to stop working I am not able to cancel the Alarmmanager. I tried it for active and passive but I do not know how to cancel it.
Here I leave the code.
MAIN CODE.
boolean alarmRunning = (PendingIntent.getBroadcast(this.context, 0, alarm, PendingIntent.FLAG_NO_CREATE) != null);
if(alarmRunning == false) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.context, 0, alarm, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 59000, pendingIntent);
}
CLOSURE CODE FROM ANOTHER ACTIVITY.
Intent intent = new Intent(this, Main.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
I hope you can help me out and thanks in advance.