Bug 925012 - Force execution of pending BrowserSearch fragment removals before re-adding. r=lucasr a=lsblakk
authorBrian Nicholson <bnicholson@mozilla.com>
Fri, 18 Oct 2013 11:39:32 -0700
changeset 155873 87072df529bbed97db4f6a8d0f1da992ca59b045
parent 155872 b849074cee927af9b1ad6c6333790f9b113886b6
child 155874 ff149163d8e098dd65740691f50607d3787b1458
push id4456
push userlrocha@mozilla.com
push dateTue, 22 Oct 2013 09:41:03 +0000
treeherdermozilla-aurora@ff149163d8e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, lsblakk
bugs925012
milestone26.0a2
Bug 925012 - Force execution of pending BrowserSearch fragment removals before re-adding. r=lucasr a=lsblakk
mobile/android/base/BrowserApp.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -47,16 +47,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.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -1579,18 +1580,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;
         }