Android:AlarmManager 陷阱
在我的闹钟中,我使用以下代码来启用信号:
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);
}
我的接收器启动服务,播放音乐并显示“关闭”对话框。
context.startService(wakePlayer);
context.startActivity(wakeWindow);
这段代码的问题是有时会失败。我的意思是它不会启动音乐并显示对话框。有人遇到过同样的问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论