Start Time of Android app Performance

Source: Internet
Author: User

The startup time of an application is also an important indicator to measure the performance of the application, so let's take a look at how to get the time required for a program to start.

There are several methods to get the start time of a program. For details, see the following analysis:


Method 1: Get it through log.

Idea: record the start time and end time and calculate the time difference to get the start time.

Add log. e ("TAG", "" finish) to the last line of the onCreate () method, and view the log output in logcat to calculate the program startup time.

This method requires source code and is relatively primitive and is not recommended.


Method 2: Get the start time through ActivityManager training.

Train of Thought: Get the start time by calculating the time difference between the time when the rotation training does not appear and the time when it appears.

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ActivityManager am = (ActivityManager) getSystemService(this.ACTIVITY_SERVICE);List
 
   appinfo = am.getRunningAppProcesses();for (RunningAppProcessInfo runningAppProcessInfo : appinfo) {if (runningAppProcessInfo.processName.equals("yourpakagename")) {Log.e("TAG", System.currentTimeMillis() + "");}}}
 

This method is more accurate than the first method without the source code.


Method 3: Call the application (shell am) to obtain the startup time.

Idea: Call the Android shell command to get the app startup time.

adb shell am start -W -n yourpakagename/MainActivity
The start time obtained by this method is very accurate and accurate to milliseconds.


To sum up the three methods, method 1 is relatively primitive but easy to operate. It is suitable for beginners to use black box tests with low requirements. method 2 has high technical requirements, this method is suitable for apps developed on mobile phones to detect the startup time of other apps. Method 3 is suitable for batch viewing the application startup time. The disadvantage is that LanuchActivity of all applications must be obtained.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.