AlarmManager:提供了访问系统报警服务,可以实现系统定时做出某种动作,即可以使你的应用可以在特定时间启动运行。
pendingIntent:可以看做对Intent的重新封装类,与intent不同的是,pendingIntent已保存了相应的动作,而intent需要在执行startActivity、startService或sendBroadcast才能使Intent做出相应动作,pendingIntent只能通过getActivity,getBroadcast ,getService来得到pendingintent的实例,pendingIntent详细参考http://blog.csdn.net/zeng622peng/article/details/6180190
alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE);//得到实例
方法
一次性闹钟
参数一:定时方式 ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC RTC_WAKEUP
参数二:间隔时间
参数三:特定动作
public void set(int type, long triggerAtMillis, PendingIntent operation)
重复闹钟
参数一:定时方式 ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC RTC_WAKEUP
参数二:触发时间
参数三:间隔时间
参数四:特定动作
public void setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
重复闹钟 //已建议弃用
与setRepeating()类似
参数一:定时方式 ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC RTC_WAKEUP
参数二:触发时间
参数三:间隔时间
参数四:特定动作
public void setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
定时方式 type参考http://blog.csdn.net/wangxingwu_314/article/details/8060312