使用 android TimerTask 和 Timer 防止最终用户对计时器进行操作 [英] Preventing timer manipulation from end user with android TimerTask and Timer

查看:37
本文介绍了使用 android TimerTask 和 Timer 防止最终用户对计时器进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确保应该在 android 操作系统上运行 x 时间的任务在 x 时间段内运行,而无需用户操作日期和时间?例如,如果我想让这个计时器持续运行 24 小时,然后通知用户 24 小时已经过去,即使手机关闭了一个小时,用户也会将其重新打开并将系统时间向前设置 2 小时,此计时器仍会指示 24 小时固定时间何时过去,而无需用户操作系统日期/时间,也无需连接到互联网来验证是否已经过去了适当的时间.

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.

谢谢

推荐答案

这里是流程/算法.

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.

这篇关于使用 android TimerTask 和 Timer 防止最终用户对计时器进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆