In my application i pass a time in milleseconds to this method below, but when this method is called , the BroadCastReciever that i registered for this intent in my manifest is called right away, shutting off audio playback the second it even starts. (the BroadcastReciever’s purpose is to stop audio playback, but at the selected time that gets passed to the alarmmanager via the method below…)
Ive tried similar configurations, including getService, but still even that component gets called right away when setting an alarmanager for that component.
I occasionally get ANR with nullpointer exception, because the BroadcastReciever that stops playback attempts to stop the MediaPlayer object that hasnt even been initialized yet, since the pendingintent to stop playback gets called right away when setting it.
private void makeAlarm(long timeInFuture){
Intent INTENT = new Intent("myapp.stopplayback");
AlarmManager alarmManager=(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, INTENT, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeInFuture, pi);
}
As written in docs:
So, you should provide real time of alarm. If you want alarm in a minute later, provide