When creating an AlarmManager inside the MainActivity everything works fine. At the specified time, another activation is launched:
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(MainActivity.this, AlarmActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, iterator, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, key, pendingIntent); But if you do the same not from the MainActivity , but, for example, from the same class AlarmActivity , then upon reaching the specified time, nothing happens.
Intent intent = new Intent ( this , AlarmActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity ( this , ...);
The problem is most likely in the context , but what should it be if the intent is not created from the MainActivity ? Tried it through this and via AlarmActivity.this , and via getApplicationContext()
UPDATE
On alarmActivity there is a button "Postpone", when clicked, the alarm is updated and the activity closes
public void hold(View view) { long hold = 0; long currentTime = new Date().getTime(); if (spinner.getSelectedItemPosition() == 0) //hold = 5 * 60 * 1000; hold = 5000; //for test else if (spinner.getSelectedItemPosition() == 1) hold = 10 * 60 * 1000; else if (spinner.getSelectedItemPosition() == 2) hold = 15 * 60 * 1000; else if (spinner.getSelectedItemPosition() == 3) hold = 30 * 60 * 1000; else if (spinner.getSelectedItemPosition() == 4) hold = 60 * 60 * 1000; currentTime += hold; AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, AlarmActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, currentTime, pendingIntent); this.finish(); }