java - Timer how long it takes to load another activity -
i wanted you. know how can time how long take load activity
example:
activity a
oncreate.... intent myintent = new intent(this, activityb.class); finish(); //start timer here ************** startactivity(myintent); ...
activity b
oncrate..... loadplayer(); .... private void loadplayer() { //player has been loaded //stop time , print log cat *************** log.i("timer", "it taken = "); }
i created small helper class works perfect needs in couple of simple apps:
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 key: " + key); } } }
to use profiler.startprofiling("activityb")
, when consider it's loaded -> profiler.endprofiling("activityb")
Comments
Post a Comment