Bharat Pawar Bharat Pawar - 4 months ago 37
Android Question

Launch Time of an app

What is the best way to launch an app and calculate its launch time in android(if it can be done with some code,then its better)

Answer

Hmm - first, to be more precise, I should point out that in Android you start activities, rather than applications!

So, as your entry point to your application is the Activity which handles the LAUNCH intent, one could interpret your question as "how to measure activity start up time".

For this, I suggest to look at an Activities lifecycle here: http://developer.android.com/intl/fr/reference/android/app/Activity.html#ActivityLifecycle.

Looking at the nice graph there, you see that startup time is essentially the time that is spent in onCreate(), onStart() and onResume().

To measure that, I would suggest to use traceview as this will really show you in all its detail where you spent your time! Start tracing using Debug.startMethodTracing("startUp"); in the beginning of onCreate() and end tracing at the end of onResume() with Debug.stopMethodTracing();.

Because onCreate() is only called once per instance, you don't even have to worry about multiple calls to onResume() in case this activity will be put to the background as you will call the stop method twice, which is no harm!

Have fun - I like the possibilities of traceview very much!

Comments