AlarmManager 定時報警服務

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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章