In my app I need to set alarm, and show notification in status bar. I store scheduled events in data base, and remove event when notification shows up.
When I turn off device, and turn on again. The list in base exists, but alarm event never triggers. It seems like pending events are canceled when I turned off device.
How to prevent this? I need to show notification whenever the devices is on, and time for alarm comes up.
This is how I set alarm:
Intent intent = new Intent(activity, TimeAlarm.class);
intent.putExtra(SHOW_NAME, showName);
intent.putExtra(SHOW_START_TIME, showStartTime);
intent.putExtra(CHANNEL_NAME, channelName);
intent.putExtra(VIBRATION_ENABLED, isVibrate);
intent.putExtra(SOUND_ENABLED, isSound);
int alarmId = (int) System.currentTimeMillis();
intent.putExtra(ALARM_ID, alarmId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(activity,
alarmId, intent, PendingIntent.FLAG_ONE_SHOT);
am.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + delayMilis, pendingIntent);
In Manifest file I have only this:
<receiver
android:name="com.moleandroid.tvprogramgui.alarm.TimeAlarm"
/receiver>
TimeAlarm class is my receiver, and from there I show notification in status bar.
Any idea whats wrong?