我想像你一样。你知道我如何计算加载另一个 Activity 需要多长时间
示例:
Activity A
onCreate....
Intent myIntent = new Intent(this, ActivityB.class);
finish();
//START THE TIMER HERE **************
startActivity(myIntent);
...
Activity B
onCrate.....
loadPlayer();
....
private void loadPlayer() {
//Player has been loaded
//STOP THE TIME AND PRINT TO LOG CAT ***************
log.i("Timer", "It taken = ");
}
最佳答案
我创建了一个小型帮助程序类,它可以完美地满足我在几个简单应用程序中的需求:
public class Profiler {
private static HashMap<String, Long> profileTimes;
public static void startProfiling(String key) {
profileTimes.put(key, System.currentTimeMillis());
}
public static void endProfiling(String key) {
endProfiling(key, "");
}
public static void endProfiling(String key, String desc) {
if (profileTimes.get(key) != null) {
long time = System.currentTimeMillis() - profileTimes.get(key);
Log.d("profiling", key + ", " + desc + ": time: " + (time / 1000) + "." + String.format("%03d", (time % 1000)));
profileTimes.remove(key);
} else {
Log.e("profiling", "NO profiling found for key: " + key);
}
}
}
要使用它,只需执行 Profiler.startProfiling("ActivityB")
,当您认为它已加载时 -> Profiler.endProfiling("ActivityB")
关于java - 计时器加载另一个 Activity 需要多长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29381981/