am a844e8a6: am 255dba84: am 2c74ee56: Prevent EmailAddressAdapter from leaking cursors; load in bg

Merge commit 'a844e8a69bca89ddb02a7e31141e383ff636d024'

* commit 'a844e8a69bca89ddb02a7e31141e383ff636d024':
  Prevent EmailAddressAdapter from leaking cursors; load in bg
This commit is contained in:
Marc Blank 2009-10-13 17:02:47 -07:00 committed by Android Git Automerger
commit 5c1f6f23c3
2 changed files with 21 additions and 5 deletions

View File

@ -69,6 +69,15 @@ public class EmailAddressAdapter extends ResourceCursorAdapter {
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String filter = constraint == null ? "" : constraint.toString();
Uri uri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, Uri.encode(filter));
return mContentResolver.query(uri, PROJECTION, null, null, SORT_ORDER);
Cursor c = mContentResolver.query(uri, PROJECTION, null, null, SORT_ORDER);
// To prevent expensive execution in the UI thread
// Cursors get lazily executed, so if you don't call anything on the cursor before
// returning it from the background thread you'll have a complied program for the cursor,
// but it won't have been executed to generate the data yet. Often the execution is more
// expensive than the compilation...
if (c != null) {
c.getCount();
}
return c;
}
}

View File

@ -148,6 +148,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
private AsyncTask mSaveMessageTask;
private AsyncTask mLoadMessageTask;
private EmailAddressAdapter mAddressAdapter;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
@ -375,6 +377,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
cancelTask(mLoadMessageTask);
mLoadMessageTask = null;
// don't cancel mSaveMessageTask, let it do its job to the end.
// Make sure the adapter doesn't leak its cursor
if (mAddressAdapter != null) {
mAddressAdapter.changeCursor(null);
}
}
/**
@ -511,18 +518,18 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
mQuotedTextDelete.setOnClickListener(this);
EmailAddressAdapter addressAdapter = new EmailAddressAdapter(this);
mAddressAdapter = new EmailAddressAdapter(this);
EmailAddressValidator addressValidator = new EmailAddressValidator();
mToView.setAdapter(addressAdapter);
mToView.setAdapter(mAddressAdapter);
mToView.setTokenizer(new Rfc822Tokenizer());
mToView.setValidator(addressValidator);
mCcView.setAdapter(addressAdapter);
mCcView.setAdapter(mAddressAdapter);
mCcView.setTokenizer(new Rfc822Tokenizer());
mCcView.setValidator(addressValidator);
mBccView.setAdapter(addressAdapter);
mBccView.setAdapter(mAddressAdapter);
mBccView.setTokenizer(new Rfc822Tokenizer());
mBccView.setValidator(addressValidator);