I can detect change clock time when app in foreground, background, or kill from Recent App
by using android.intent.action.TIME_SET
follow here.
However, if I Force Stop
app in Setting->Apps I can not receive this broadcast anymore.
Currently, I want to detect user change clock time come back to my app after ForceStop so I do
long deltaTimeBeetweenCurrentTimeAndTimeSinceReboot = System.currentTimeMillis() - SystemClock.elapsedRealtime();
long oldDelta = mSharedPreference.getDeltaTimeBeetweenCurrentTimeAndTimeSinceReboot();
if(deltaTimeBeetweenCurrentTimeAndRebootTime - oldDelta > 5000){
// clock time change
}
Idea is I saved a delta between currently time (System.currentTimeMillis()
) and time since reboot (SystemClock.elapsedRealtime()
). Every time I open app, I will compare oldDelta and newDelta (except the first time install). It work well in case: User Fore Stop
app->Change time->come back to app.
However, there is still have 1 case that is: User Fore Stop
app -> Change the clock time -> Reboot device -> Open my app. At this time I can not use the above method to check the clock time have changed because after reboot the SystemClock.elapsedRealtime() will reset. How can I detect clock time have changed in that case?
Any help or suggestion would be great appreciate.