0

Is there a way to maintain a timer which is not dependant on the current date ? i will explain the situation for u.i have to send a subscribe for all the contacts of the android phone. during bootup.the condition is if the last subscribe was sent before more than 120secs, then only the subscribe will be sent. or else it should wait till 120 secs. now the problem occurs if the user changes the current date/time. then how do i calculate the 120 secs?? is there any other way you can think of?? please help.

scooby
  • 493
  • 11
  • 31

2 Answers2

0

Is your app alive during the 120 seconds?

If alive then you can try CountDownTimer and sample code

If your app is not alive, then you may want to look at AlarmManager configured to use ELAPSED_REALTIME and sample code

Hope this helps.

EDIT: Get time from web

Community
  • 1
  • 1
XiaoChuan Yu
  • 3,951
  • 1
  • 32
  • 44
  • no, it might happen that the phone is switched off within that time period(120 secs) as well. – scooby Mar 01 '12 at 09:08
  • hii. tell me one thing.. will this alarmManager still work if the date/time is set without rebooting??? – scooby Mar 01 '12 at 09:16
  • ELAPSED_REALTIME is independent of system time, its the relative amount of time since the system/phone was booted. If you have a usage scenario where user shuts off phone then you may to have resort to getting time from internet source; see link in my edited answer. – XiaoChuan Yu Mar 01 '12 at 19:47
0

How about using uptimeMillis() (click)?

neciu
  • 4,373
  • 2
  • 24
  • 33