Preventing timer manipulation from end user with android TimerTask and Timer

无人久伴 提交于 2019-12-20 04:22:00

问题


How can one ensure that a task that is supposed to run for x amount of time on an android os be run for that x period without user manipulation of date and time? For example, if I want this timer to run for 24 hours solid and then advise the user that 24h has passed, even if the phone is off for an hour, the user then turns it back on and sets the system time forward 2 hours, this timer would still indicate when that solid 24 hour period had passed without the user manipulating the system date/time and without connecting to the internet to verify the proper amount of time has passed.

Thanks


回答1:


Here is flow/algorithm.

1) You need to store time of timer first initiated some where, probably database and let timer run for 24 hours.
    a) assuming phone not turned off, timer continues
    b) Assuming phone turned off and turned on
        b1) Get initial timer started time from database, then calculate how much time left for 24 hours. 
        b2) Initiate timer again with left time.


来源:https://stackoverflow.com/questions/13716546/preventing-timer-manipulation-from-end-user-with-android-timertask-and-timer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!