Android traceview usage and listview Performance Optimization Test (1)

Source: Internet
Author: User

I read the following document today, saying that traceview is of great help to program performance and optimization:

I am too lazy, and I have not continued to read this article. I have Baidu's traceview usage skills, a lot of resources, and I will introduce how to use it.

Recommended: http://blog.csdn.net/itachi85/article/details/6857324

Of course, the specific steps are as follows:

I. When creating AVD, the memory size for the SD card is increased because the files generated by Debug. Raceview later may be large.

2. Write a test program:

Debug.startMethodTracing();

There must be an end when there is a start. If debug. stopmethodtracing () is not used, the dmtrace. trace file will not appear in the root directory of the SD card.

 

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>  

 

Note: We recommend that you call debug in the onpuse () method. stopmethodtracing: it is not recommended to call the ondestory () or onstop () method, because it is possible that the program may not necessarily use ondestory or onstop in an inexplicable situation, so it is more reliable in onpuse.

3: Do not worry before running: Remember to add permissions to the SD card or else the permission exception will be thrown:

 

4. You have generated the dmtrace. trace file! What do you think? Google is user-friendly. There is a traceview tool in the tools of Android development tools that you only need

CMD to this directory, and then import the dmtrace. trace file on the SD card to a path in the PC (default: C \ dmtrace. Trace)

Then run traceview c: \ dmtrace. Trace (your own path strength)

Things: Then you can see the following interface:

Check whether the interface is dizzy! :

What about this! At the beginning, I did not know what to read, nor did I know how to read it. I did not understand Baidu:

Originally:

In the right-hand statistical field of traceview:
Exclusive: the time when the same-level function itself runs, that is, in addition to the time when the function itself runs and the time when the sub-function is called
Name: Lists All call items. The preceding number is the number. Expand to show that the parent and children subitems are called and called.
Incl: percentage of the time taken to calculate the total time.
Excl: percentage of the total execution time.
Cballs + recur cballs/Total: number of calls and repeated calls time/call: Total time. (MS) Do you understand?

I also share with you my experience that you have seen so much data below and don't know what to expect. Is there a Filter column at the bottom, if you don't have him, your eyes will be lost, because there is too much data.

The above is a simple traceview usage:

 

Let's use him to verify if there is such a magic!

If you don't verify others, use him to verify the performance of my listview. This problem is very difficult for me for a long time, because the listview optimization network provides a lot of different versions and opinions:

 

About listview optimization:

Http://www.cnblogs.com/over140/archive/2011/03/23/1991100.html

package com.liao.listadpter;import java.util.ArrayList;import java.util.List;import android.app.ListActivity;import android.os.Bundle;import android.os.Debug;public class MainActivity extends ListActivity {    private List<String> data;/** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //setContentView(R.layout.main);    Debug.startMethodTracing();        initData();        initadapter();          }    public void initData() {data = new ArrayList<String>();for (int i = 0; i < 1000; i++) {data.add("test: " + i);}}public void initadapter() {TestAdapter testAdapter = new TestAdapter(data, MainActivity.this);this.setListAdapter(testAdapter);}@Override    protected void onPause() {    // TODO Auto-generated method stub    super.onPause();    Debug.stopMethodTracing();    }}

Adapter Information

package com.liao.listadpter;import java.util.List;import org.w3c.dom.Text;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;public class TestAdapter extends BaseAdapter{private List<String> listData;private Context context;private LayoutInflater inflater;private LinearLayout layout;TestAdapter(List<String> listData ,Context context){this.listData =listData;this.context =context;inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);}public int getCount() {// TODO Auto-generated method stubreturn listData.size();}public Object getItem(int position) {// TODO Auto-generated method stubreturn listData.get(position);}public long getItemId(int position) {// TODO Auto-generated method stubreturn position;}public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubif(convertView ==null){layout = (LinearLayout) inflater.inflate(R.layout.listview, null);}else{layout = (LinearLayout) convertView;} int id= position %2==1? R.drawable.icon: R.drawable.default_head; ((ImageView) layout.findViewById(R.id.iamge)).setImageResource(id); ((TextView) layout.findViewById(R.id.text)).setText(listData.get(position));;//TextView text = (TextView) layout.findViewById(R.id.text);//ImageView view= (ImageView) layout.findViewById(R.id.iamge);////text.setText(listData.get(position));return layout;} static class ViewHoder{public TextView text;public ImageView view;}}

Below is the XML

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation ="horizontal"    ><TextView      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="list 1"    android:id ="@+id/text"    android:layout_gravity = "center_vertical"    /><ImageView      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id ="@+id/iamge"    android:src ="@drawable/icon"    /></LinearLayout>

:

 

Article Limited: transfer next: http://blog.csdn.net/liao3841054/article/details/7162428

Reprinted please declare access: http://blog.csdn.net/liao3841054/article/details/7162181

 

 

 

 

 

Related Article

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.