gpt4 book ai didi

java - 当通过按钮将 SystemClock.elapsedRealtime 显示到 TextView 中时,我得到一个非常大的值

转载 作者:行者123 更新时间:2023-12-02 02:53:20 26 4
gpt4 key购买 nike

当尝试显示我的程序的运行时间时,单击按钮后我收到一个非常高的值“119660898”。如果我等待 3 秒并重新单击按钮,总数将按预期增加大约 3 秒。

谁能解释一下为什么初始值这么高?下面是我在按钮中使用的代码。

        FinalTime = SystemClock.elapsedRealtime();

TextView text = (TextView) findViewById(R.id.textView1);
text.setText("n " + FinalTime);

最佳答案

When trying to display the elapsed time of my program, after clicking the button im receiving a very high value [...] Can anyone explain why the initial value is so high?

因为它不是您的程序的运行时间。来自 docs :

elapsedRealtime() and elapsedRealtimeNanos() return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.

如果您想知道自应用启动以来耗时,您需要在应用启动时保存 SystemClock.elapsedRealtime() 并随后计算增量。

关于java - 当通过按钮将 SystemClock.elapsedRealtime 显示到 TextView 中时,我得到一个非常大的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43457701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com