简体   繁体   中英

How can I track the ActivityManager loading time of my app?

I would like to track how much time take my app to start, but I would like to track this specific info defined here: https://developer.android.com/topic/performance/vitals/launch-time In order to have better graphics about it and add custom info to it. What I have tried?

I have tried to add a timer between onCreate method and onResume but the time obtained is the half of the time tracked by the system "Activity Manager: Displayed"

What can I do to have those values programmatically?

在此处输入图像描述

You should count the time between Application.onCreate() to end of Activity.onCreate() to get the cold startup time. Please read here for more info on this.

Let me explain. In your application class:

class YourApplication: Application() {

public static long starttime = 0;

@Override
    public void onCreate() {
    starttime = SystemClock.elapsedRealtime();
}
}

In your launcher activity class, upon completion of onCreate method:

class MainActivity : Activity() {

       @Override
       public void onCreate() {
       long timeelapsed = (SystemClock.elapsedRealtime() - YourApplication.starttime);
     Log.i("TEST", "your time : "+ timeelapsed)
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM