Android: AlarmManager pitfalls [duplicate]
In my alarm clock I use the following code to enable signals:
Intent i = new Intent(AlarmReciever.ACTION_WAKEUP);
i.putExtra(AlarmDao.ID_COLUMN, a.getId());
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, a.getId(), i, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = a.getNextAlarm();
if(cal!=null){
AlarmManager alarmManager = (AlarmManager)
context.getSystemService(context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
if(toast) showToast(context, cal);
}
My receiver starts service, that plays music and show "switch off" dialog.
context.startService(wakePlayer);
context.startActivity(wakeWindow);
The problem with this code is that sometimes it fails. I mean it doesn't start music and show the dialog. Have anyone faced the same problem?
精彩评论