读书人

android 定时器的兑现

发布时间: 2012-06-27 14:20:09 作者: rapoo

android 定时器的实现

?


<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> Intent intent =new Intent(Main.this, alarmreceiver.class); intent.setAction("repeating"); PendingIntent sender=PendingIntent .getBroadcast(Main.this, 0, intent, 0); AlarmManager alarm=(AlarmManager)getSystemService(ALARM_SERVICE); alarm.cancel(sender);? 1 楼 chaosmonkey 2011-12-31 楼主有没有试试Handler的post系列函数?不知道他们会不会受到电源管理的影响? 2 楼 407827531 2012-01-04 chaosmonkey 写道楼主有没有试试Handler的post系列函数?不知道他们会不会受到电源管理的影响?
博客中,这段是不受电源管理影响的
2.2setRepeating是的类型设置为AlarmManager.ELAPSED_REALTIME_WAKEUP


AlarmManager am =
(AlarmManager)getSystemService(ALARM_SERVICE);

am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, 5*1000,
sender);

拔掉USB线,按下电源键,过一点时间再次打开屏幕,发现定时器一直在计数。

如此看来,使用WAKEUP才能保证自己想要的定时器一直工作,但是肯定会引起耗电量的增加

读书人网 >Android

热点推荐