Android闹铃程序之找坑与填坑

很好的的一个 全实现:Alarm Klock: http://code.google.com/p/kraigsandroid/

  1. 设置闹钟使用AlarmManager.set()函数,它的triggerAtTime参数,如果要用 Calendar.getTimesInMillis()获得,就必须先设置Calendar对象,例如要让闹钟在当天的16:30分启动,就要设置 HOUR_OF_DAY(16)、MINUTE(30)、MILLISECOND(0),特别是HOUR_OF_DAY,我一开始误用了HOUR,这是 12进制计时方法,HOUR_OF_DAY是24进制计时方法。
  2. 针对同一个PendingIntent,AlarmManager.set()函数不能设置多个alarm。调用该函数时,假如已经有old alarm使用相同的PendingIntent,会先取消(cancel)old alarm,然后再设置新的alarm。如何判断是否已经有相同的PendingIntent,请看下条。
  3. 取消alarm使用AlarmManager.cancel()函数,传入参数是个PendingIntent实例。该函数会将所有跟这个 PendingIntent相同的Alarm全部取消,怎么判断两者是否相同,android使用的是intent.filterEquals(),具体 就是判断两个PendingIntent的action、data、type、class和category是否完全相同。
  4. 在AndroidManifest.xml中静态注册BroadcastReceiver时,一定使用android:process=":xxx"属性,因为SDK已注明:If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the broadcast receiver runs in that process.

猜你喜欢

转载自badxy.iteye.com/blog/1886616