User time change detection after Force Stop application

I can detect the time change time when the application is in the foreground, background or kill Recent Appusing android.intent.action.TIME_SETit follows here .
However, if I’m an Force Stopapplication 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){
    // clock time change
}

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 Stopapp-> Change time-> return to the application.

However, there is another case: User Fore Stopapp → 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.

+4
2

. , . :
.

, :

" , - / ?"

" , - , ?"

-. , Force-Stop + , , reset .

, .

+3

( - ). , , ( ). "" , , .

, .

+1

Source: https://habr.com/ru/post/1688849/


All Articles