I can detect the time change time when the application is in the foreground, background or kill Recent App
using android.intent.action.TIME_SET
it follows here .
However, if I’m an Force Stop
application in Settings-> Applications , I can no longer receive this broadcast.
Currently, I want the user clock replacement time to be returned to my application after ForceStop, so I do
long deltaTimeBeetweenCurrentTimeAndTimeSinceReboot = System.currentTimeMillis() - SystemClock.elapsedRealtime();
long oldDelta = mSharedPreference.getDeltaTimeBeetweenCurrentTimeAndTimeSinceReboot();
if(deltaTimeBeetweenCurrentTimeAndRebootTime - oldDelta > 5000){
}
Idea: I saved the delta between the current time ( System.currentTimeMillis()
) and the time since the reboot ( SystemClock.elapsedRealtime()
). Each time I open the application, I will compare oldDelta and newDelta (except for the first installation). It works well in the case: User Fore Stop
app-> Change time-> return to the application.
However, there is another case: User Fore Stop
app → Change clock time → Reboot device → Open my application. At this time, I cannot use the above method to check if the time of the clock has changed, because after rebooting SystemClock.elapsedRealtime () will reset, How can I determine the time of the beat in this case?
Any help or suggestion would be greatly appreciated.