title: Android - How to make an activity to load faster?
body: <p>I am currently working on an SMS app which will be quite similar to stock sms app.</p>
  
  <p>But the problem is my app is loading much slower than the stock(inbuilt) app.</p>
  
  <p>Here is my app's code :-</p>
  
  <pre><code>public class ThreadData extends ListActivity
  {
  private static final Uri SMS_URI = Uri.parse("content://sms");
  ArrayList&lt;String&gt; bodies = new ArrayList&lt;String&gt;();
  MySMSAdapter adapter;
  String name;
  
  public void onCreate(Bundle bundle)
  {
      super.onCreate(bundle);
      setContentView(R.layout.threadlist);
      Bundle extras = getIntent().getExtras();
      if(extras != null)
      {
          name = extras.getString("address");
      }
      Cursor cursor = getContentResolver().query(SMS_URI, null, null, null, "date ASC");
      startManagingCursor(cursor);
      while (cursor.moveToNext())
      {
          String Id = cursor.getString(cursor.getColumnIndex("_id"));
          String address = cursor.getString(cursor.getColumnIndex("address"));
          String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
          String personName = getPersonName(Id,  address);
          if(personName.equals(name))
          {
              bodies.add(body);
          }
      }
      //adapter = new MySMSAdapter(this, bodies);
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.sms_inbox, R.id.row, bodies);
      ListView listView = getListView();
      listView.setAdapter(adapter);
  }
  public String getPersonName(String id, String address)
  {
          if(id==null)
          {
              if(address != null)
              {
                  return PhoneNumberUtils.formatNumber(address);
              }
              else
              {
                  return null;
              }
          }
  
          Cursor c = this.getContentResolver().query(Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, address),
                     new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
  
          if(c != null)
          {
              try
              {
                  if(c.getCount() &gt; 0)
                  {
                      c.moveToFirst();
                      return c.getString(0);
                  }
              }
              finally
              {
                  c.close();
              }
          }
          if(address != null)
          {
              return PhoneNumberUtils.formatNumber(address);
          }
          return null;
  }
  
  }
  </code></pre>
  
  <p>My custom adapter :-</p>
  
  <pre><code>public class MySMSAdapter extends BaseAdapter
  {
  private Activity activity;
  private ArrayList&lt;String&gt; data;
  LayoutInflater inflater;
  
  public MySMSAdapter(Activity a, ArrayList&lt;String&gt; arrayList)
  {
      activity = a;
      data = arrayList;
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  public int getCount()
  {
      return data.size();  //To change body of implemented methods use File | Settings | File Templates.
  }
  
  public Object getItem(int i)
  {
      return data.get(i);  //To change body of implemented methods use File | Settings | File Templates.
  }
  
  public long getItemId(int i)
  {
      return i;
  }
  
  public static class ViewHolder
  {
      public TextView textView;
  }
  
  public View getView(final int i, View view, ViewGroup viewGroup)
  {
      View row = view;
      final ViewHolder holder;
      if(view==null)
      {
          row = inflater.inflate(R.layout.sms_inbox, viewGroup, false);
          holder = new ViewHolder();
          holder.textView = (TextView)row.findViewById(R.id.row);
          row.setTag(holder);
      }
      else
      {
          holder = (ViewHolder)row.getTag();
      }
  
      holder.textView.setText(data.get(i));
      return row;
  }
  }
  </code></pre>
  
  <p>In my class i tried loading List with both the options(custom adapter as well as ArrayAdapter) But in both case my app is loading very slow. How to load it faster? I may prefer solution for my custom adapter as in future i may need few things to add in my layout like photos and other stuff.</p>
  
  <p>Thanks. Please Help!!</p>