【发布时间】:2015-08-01 06:28:10
【问题描述】:
Android 文档中关于 getElapsedCpuTime() 的说明
返回此进程运行的经过的毫秒数。
我尝试使用 getElapsedCpuTime(),以毫秒为单位的时间相当混乱。很多(4 到 5)秒后,返回的经过时间只有 2000 左右。要么它比原始毫秒慢(1 秒内 1000 毫秒),要么我在正确理解方面有问题?
我只是在测试每次单击按钮时获取当前 cpu 运行时间,代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.build_data_view);
Button btn = (Button) findViewById(R.id.refresh);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String elapsedCpuTime = android.os.Process.getElapsedCpuTime()
+ "";
((TextView) findViewById(R.id.build_data))
.setText(elapsedCpuTime);
}
});
}
【问题讨论】:
标签: java android time milliseconds