Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the previous (old) time after changing the time

I can get the time change events with the help of broadcast events (ACTION_TIME_CHANGED and ACTION_DATE_CHANGED).

I need to get the previous time after time change. For example, the current time is 10:00. I am going to change time to 12:00. After time change, time will be changed to 12:00, but I need to get the previous time (10:00) at the time of time change.

Note: Time can be changed from any other app or from settings.

like image 297
Finder Avatar asked Nov 02 '22 02:11

Finder


1 Answers

Maybe the solution I found can help you:

(Is there a way to detect when the user has changed the clock time on their device?)

The above solution could work setting a static variable on BOOT of device with System.currentTimeMillis(), and sum with SystemClock.elapsedRealtime(). With this sum you have the before time.

But there is a problem (I don't know if it matters to you), if the user does not reboot the device, then your diff will be == 0 and you will not be able to have this diff between old and actual System.currentTimeMillis().

like image 102
JonasOliveira Avatar answered Nov 12 '22 05:11

JonasOliveira