Bug 746946 - Force AsyncTask onPostExecute to only touch UI on the main thread. r=mfinkle a=akeybl
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 26 Apr 2012 16:20:03 -0400
changeset 95581 68854a10e0cba394044dc05f3ec4d0e9ed639716
parent 95580 b8d1bce48c2153eb0c41233ff97eff306c47f0ae
child 95582 a3a4c8efa2394ec29171284c38f4ca2afcc2329d
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, akeybl
bugs746946
milestone14.0a2
Bug 746946 - Force AsyncTask onPostExecute to only touch UI on the main thread. r=mfinkle a=akeybl
mobile/android/base/AwesomeBarTabs.java
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -351,51 +351,58 @@ public class AwesomeBarTabs extends TabH
         }
 
         @Override
         protected Cursor doInBackground(Void... arg0) {
             return BrowserDB.getBookmarksInFolder(mContentResolver, mFolderId);
         }
 
         @Override
-        protected void onPostExecute(Cursor cursor) {
-            ListView list = (ListView) findViewById(R.id.bookmarks_list);
-            list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                    handleBookmarkItemClick(parent, view, position, id);
+        protected void onPostExecute(final Cursor cursor) {
+            final ListView list = (ListView) findViewById(R.id.bookmarks_list);
+
+            // Hack: force this to the main thread, even though it should already be on it
+            GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+                public void run() {
+                    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                            handleBookmarkItemClick(parent, view, position, id);
+                        }
+                    });
+                    
+                    // We need to add the header before we set the adapter, hence make it null
+                    list.setAdapter(null);
+
+                    if (mBookmarksAdapter == null) {
+                        mBookmarksAdapter = new BookmarksListAdapter(mContext, cursor);
+                    } else {
+                        mBookmarksAdapter.changeCursor(cursor);
+                    }
+
+                    LinearLayout headerView = mBookmarksAdapter.getHeaderView();
+                    if (headerView == null) {
+                        headerView = (LinearLayout) mInflater.inflate(R.layout.awesomebar_header_row, null);
+                        mBookmarksAdapter.setHeaderView(headerView);
+                    }
+
+                    // Add/Remove header based on the root folder
+                    if (mFolderId == Bookmarks.FIXED_ROOT_ID) {
+                        if (list.getHeaderViewsCount() == 1)
+                            list.removeHeaderView(headerView);
+                    } else {
+                        if (list.getHeaderViewsCount() == 0)
+                            list.addHeaderView(headerView, null, true);
+
+                        ((TextView) headerView.findViewById(R.id.title)).setText(mFolderTitle);
+                    }
+
+                    list.setAdapter(mBookmarksAdapter);
                 }
             });
-            
-            // We need to add the header before we set the adapter, hence make it null
-            list.setAdapter(null);
 
-            if (mBookmarksAdapter == null) {
-                mBookmarksAdapter = new BookmarksListAdapter(mContext, cursor);
-            } else {
-                mBookmarksAdapter.changeCursor(cursor);
-            }
-
-            LinearLayout headerView = mBookmarksAdapter.getHeaderView();
-            if (headerView == null) {
-                headerView = (LinearLayout) mInflater.inflate(R.layout.awesomebar_header_row, null);
-                mBookmarksAdapter.setHeaderView(headerView);
-            }
-
-            // Add/Remove header based on the root folder
-            if (mFolderId == Bookmarks.FIXED_ROOT_ID) {
-                if (list.getHeaderViewsCount() == 1)
-                    list.removeHeaderView(headerView);
-            } else {
-                if (list.getHeaderViewsCount() == 0)
-                    list.addHeaderView(headerView, null, true);
-
-                ((TextView) headerView.findViewById(R.id.title)).setText(mFolderTitle);
-            }
-
-            list.setAdapter(mBookmarksAdapter);
             mBookmarksQueryTask = null;
         }
     }
 
     private static class GroupList extends LinkedList<Map<String,String>> {
         private static final long serialVersionUID = 0L;
     }
 
@@ -557,38 +564,42 @@ public class AwesomeBarTabs extends TabH
                 new String[] { URLColumns.TITLE },
                 new int[] { R.id.title },
                 result.second
             );
 
             final ExpandableListView historyList =
                     (ExpandableListView) findViewById(R.id.history_list);
 
-            historyList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
-                public boolean onChildClick(ExpandableListView parent, View view,
-                        int groupPosition, int childPosition, long id) {
-                    handleHistoryItemClick(groupPosition, childPosition);
-                    return true;
+            // Hack: force this to the main thread, even though it should already be on it
+            GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+                public void run() {
+                    historyList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
+                        public boolean onChildClick(ExpandableListView parent, View view,
+                                int groupPosition, int childPosition, long id) {
+                            handleHistoryItemClick(groupPosition, childPosition);
+                            return true;
+                        }
+                    });
+
+                    // This is to disallow collapsing the expandable groups in the
+                    // history expandable list view to mimic simpler sections. We should
+                    // Remove this if we decide to allow expanding/collapsing groups.
+                    historyList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
+                        public boolean onGroupClick(ExpandableListView parent, View v,
+                                int groupPosition, long id) {
+                            return true;
+                        }
+                    });
+
+                    historyList.setAdapter(mHistoryAdapter);
+                    expandAllGroups(historyList);
                 }
             });
 
-            // This is to disallow collapsing the expandable groups in the
-            // history expandable list view to mimic simpler sections. We should
-            // Remove this if we decide to allow expanding/collapsing groups.
-            historyList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
-                public boolean onGroupClick(ExpandableListView parent, View v,
-                        int groupPosition, long id) {
-                    return true;
-                }
-            });
-
-            historyList.setAdapter(mHistoryAdapter);
-
-            expandAllGroups(historyList);
-
             mHistoryQueryTask = null;
         }
     }
 
     private class AwesomeBarCursorAdapter extends SimpleCursorAdapter {
         private String mSearchTerm;
 
         public AwesomeBarCursorAdapter(Context context) {