开发者

Android: AlarmManager pitfalls [duplicate]

This question already has answers here: How to get an Android WakeLock to work? (14 answers) 开发者_开发百科AlarmManager and WakeLock (3 answers) Android WakeLock (3 answers) Closed 2 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜