簡體   English   中英

重置SystemClock.currentThreadTimeMillis()

[英]resetting SystemClock.currentThreadTimeMillis()

游戲結束時,我的應用程序結尾處出現一個按鈕,該按鈕用於重置應用程序。 我已經測試過了,它除了計時器外還可以工作。 我沒有重置為“ startTime”。 我有一個用於重置游戲的按鈕,例如:

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);
}

我有一個計時器運行為:

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

當我注意到游戲頂部的時間重置為原始時間時, reset_flag確實reset_flag了幫助,但是在下一個時間點,將其更新為currentThreadTimeMillis是什么。 我確實嘗試過做SystemClock.currentThreadTimeMillis() = 0; 但這沒有用(我也沒驚訝也沒有。)

我沒有在SystemClock看到可以進行任何重置的功能。 我以為這將是一個簡單的任務,但也許並非如此,有人可以給我一些幫助嗎? 謝謝。

該時間就是線程存活的時間,請考慮使用單獨的變量進行計時。 您隨時可以將其初始化為SystemClock.currentThreadTimeMillis()並在需要顯示值時扣除SystemClock.currentThreadTimeMillis()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM