简体   繁体   English

重置SystemClock.currentThreadTimeMillis()

[英]resetting SystemClock.currentThreadTimeMillis()

I have a button that appears at the end of my app when the game is complete that is meant to reset the app. 游戏结束时,我的应用程序结尾处出现一个按钮,该按钮用于重置应用程序。 I have tested it and it works besides the timer. 我已经测试过了,它除了计时器外还可以工作。 I have does not reset to the "startTime". 我没有重置为“ startTime”。 I have a button that is used to reset the game such as: 我有一个用于重置游戏的按钮,例如:

if(resetButton.getText().equals("Restart"))
{
    reset_flag = true;
    Intent i = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);
}

I have a runnable for the timer as: 我有一个计时器运行为:

long gamerestart = SystemClock.currentThreadTimeMillis();
if(reset_flag)
{
    gamerestart = 0;
    startTime = 60000;
    flag = false;
}
timeInMilliseconds = startTime - gamerestart;

The reset_flag did help as I noticed the time at the top of the game reset to the original time but at the next time-tick it updated to whatever the currentThreadTimeMillis is. 当我注意到游戏顶部的时间重置为原始时间时, reset_flag确实reset_flag了帮助,但是在下一个时间点,将其更新为currentThreadTimeMillis是什么。 I did try doing SystemClock.currentThreadTimeMillis() = 0; 我确实尝试过做SystemClock.currentThreadTimeMillis() = 0; but that did not work ( I was not surprised it didn't either..) 但这没有用(我也没惊讶也没有。)

I did not see a function within SystemClock that would doing any resetting. 我没有在SystemClock看到可以进行任何重置的功能。 I thought this would be a simple task but maybe it is not, could anyone give me some help? 我以为这将是一个简单的任务,但也许并非如此,有人可以给我一些帮助吗? Thanks. 谢谢。

That time is how long the thread has been alive, consider using a separate variable for timing. 该时间就是线程存活的时间,请考虑使用单独的变量进行计时。 You can always initialize it to SystemClock.currentThreadTimeMillis() and deduct SystemClock.currentThreadTimeMillis() whenever you want to display the value 您随时可以将其初始化为SystemClock.currentThreadTimeMillis()并在需要显示值时扣除SystemClock.currentThreadTimeMillis()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM