From 02c844fe158d55837cf1a1c391f26556e337e55b Mon Sep 17 00:00:00 2001 From: Daisuke Miyakawa Date: Thu, 21 Jul 2011 15:10:06 -0700 Subject: Stop spawning multiple threads for photo loading This is not a fundemental fix for the issue but should mitigate our headache caused by a bunch of phono_handler threads. Bug: 5057798 Change-Id: I5f81739bf8439f6d3ee726495b23aab4d3e3d0fd --- .../src/com/android/ex/chips/BaseRecipientAdapter.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'chips/src/com/android/ex/chips/BaseRecipientAdapter.java') diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java index 6e1f821..b8194d0 100644 --- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java +++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java @@ -471,7 +471,9 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter */ private CharSequence mCurrentConstraint; - private final HandlerThread mPhotoHandlerThread; + // TODO: need to find better way to manage the thread. + private static final HandlerThread sPhotoHandlerThread = + new HandlerThread("photo_handler"); private final Handler mPhotoHandler; private final LruCache mPhotoCacheMap; @@ -514,9 +516,10 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter mContentResolver = context.getContentResolver(); mInflater = LayoutInflater.from(context); mPreferredMaxResultCount = preferredMaxResultCount; - mPhotoHandlerThread = new HandlerThread("photo_handler"); - mPhotoHandlerThread.start(); - mPhotoHandler = new Handler(mPhotoHandlerThread.getLooper()); + if (!sPhotoHandlerThread.isAlive()) { + sPhotoHandlerThread.start(); + } + mPhotoHandler = new Handler(sPhotoHandlerThread.getLooper()); mPhotoCacheMap = new LruCache(PHOTO_CACHE_SIZE); } @@ -804,13 +807,14 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter return cursor; } - public void close() { + // TODO: This won't be used at all. We should find better way to quit the thread.. + /*public void close() { mEntries = null; mPhotoCacheMap.evictAll(); - if (!mPhotoHandlerThread.quit()) { + if (!sPhotoHandlerThread.quit()) { Log.w(TAG, "Failed to quit photo handler thread, ignoring it."); } - } + }*/ @Override public int getCount() { -- cgit v1.2.3