android - start service which repeat at top of every hour and fetch information at fixed time interval -
i have setting repeated alarm manager start service fetch location , send sms writing time duration in file check alarm accuracy .
i find alarm manager not working fine , set 1 hours interval fired @ 30 min. interval . left day , find after 12'o clock alarm accuracy right. happening ??
my activity class start alarm :
enter code here public static final long alarm_trigger_at_time = systemclock.elapsedrealtime() + 20000; public static final long alarm_interval = 1000 * 60 * 60 ; alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service); intent myintent = new intent(automainactivity.this, trackerservice.class); pendingintent = pendingintent.getservice(automainactivity.this, 0, myintent, 0); alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup,alarm_trigger_at_time, 1000 * 60 * 60,pendingintent);
and service class :
traceservice : public void onstart(intent intent, int startid) { super.onstart(intent, startid); //writing in file view time java.util.date systemdates = calendar.getinstance().gettime(); simpledateformat = new simpledateformat("yyyy-mm-dd-hh:mm:ss"); currenttime = simpledateformat.format(systemdates); // create file , write current time generatenoteonsd("onstart"+currenttime+"\n","onstart.txt"); }
after executing apps @ 3:18 pm time .the file created service show alarm time . check :
alarm manager time
onstart2013-05-13-15:18:26
onstart2013-05-13-15:21:58
onstart2013-05-13-15:54:21
onstart2013-05-13-16:18:25
onstart2013-05-13-17:18:26
onstart2013-05-13-17:49:21
onstart2013-05-13-18:18:25
onstart2013-05-13-19:18:28
onstart2013-05-13-20:10:51
onstart2013-05-13-20:18:29
onstart2013-05-13-20:48:49
onstart2013-05-13-21:18:30
onstart2013-05-13-21:58:58
onstart2013-05-13-22:18:38
onstart2013-05-13-22:56:00
onstart2013-05-13-23:18:43
onstart2013-05-13-23:48:49
onstart2013-05-14-00:18:44
onstart2013-05-14-01:18:45
onstart2013-05-14-02:18:45
onstart2013-05-14-03:18:45
onstart2013-05-14-04:18:45
onstart2013-05-14-05:18:44
onstart2013-05-14-06:18:44
onstart2013-05-14-07:18:44
you can check when alarm manager start @ 15:18 pm , start again after 30 min. approx. after 12'o clock work fine !!! how fix it. need alarm start every 1 hour not before .
try alarmmanager.rtc_wakeup
once instead of alarmmanager.elapsed_realtime_wakeup
there example in : alarm manager example
Comments
Post a Comment