Bug 925012 - Force execution of pending BrowserSearch fragment removals before re-adding. r=lucasr
authorBrian Nicholson <bnicholson@mozilla.com>
Fri, 18 Oct 2013 11:39:32 -0700
changeset 151277 6cf99173cf983078c3046ca71ae5c544acf947da
parent 151276 aec9897dc66dbeca75576f9958e2797550a8b61e
child 151278 d3e3e6671c569f1427359c629839623448632c92
push id3123
push userbnicholson@mozilla.com
push dateFri, 18 Oct 2013 18:41:59 +0000
treeherderfx-team@6cf99173cf98 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs925012
milestone27.0a1
Bug 925012 - Force execution of pending BrowserSearch fragment removals before re-adding. r=lucasr
mobile/android/base/BrowserApp.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -48,16 +48,17 @@ import android.graphics.drawable.BitmapD
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.nfc.NdefMessage;
 import android.nfc.NdefRecord;
 import android.nfc.NfcAdapter;
 import android.nfc.NfcEvent;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.v4.app.FragmentManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.InputDevice;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.MotionEvent;
@@ -1641,18 +1642,26 @@ abstract public class BrowserApp extends
 
     private void showBrowserSearch() {
         if (mBrowserSearch.getUserVisibleHint()) {
             return;
         }
 
         mBrowserSearchContainer.setVisibility(View.VISIBLE);
 
-        getSupportFragmentManager().beginTransaction()
-                .add(R.id.search_container, mBrowserSearch, BROWSER_SEARCH_TAG).commitAllowingStateLoss();
+        final FragmentManager fm = getSupportFragmentManager();
+
+        // In certain situations, showBrowserSearch() can be called immediately after hideBrowserSearch()
+        // (see bug 925012). Because of an Android bug (http://code.google.com/p/android/issues/detail?id=61179),
+        // calling FragmentTransaction#add immediately after FragmentTransaction#remove won't add the fragment's
+        // view to the layout. Calling FragmentManager#executePendingTransactions before re-adding the fragment
+        // prevents this issue.
+        fm.executePendingTransactions();
+
+        fm.beginTransaction().add(R.id.search_container, mBrowserSearch, BROWSER_SEARCH_TAG).commitAllowingStateLoss();
         mBrowserSearch.setUserVisibleHint(true);
     }
 
     private void hideBrowserSearch() {
         if (!mBrowserSearch.getUserVisibleHint()) {
             return;
         }