mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
Bug 863803 - Part 1: Prevent multiple AboutHome fragments from being created after restore. r=lucasr
This commit is contained in:
parent
b1fb07137b
commit
0464db2da4
@ -123,6 +123,10 @@ abstract public class BrowserApp extends GeckoApp
|
|||||||
|
|
||||||
private Integer mPrefObserverId;
|
private Integer mPrefObserverId;
|
||||||
|
|
||||||
|
// Tag for the AboutHome fragment. The fragment is automatically attached
|
||||||
|
// after restoring from a saved state, so we use this tag to identify it.
|
||||||
|
private static final String ABOUTHOME_TAG = "abouthome";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
||||||
switch(msg) {
|
switch(msg) {
|
||||||
@ -358,13 +362,18 @@ abstract public class BrowserApp extends GeckoApp
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// AboutHome will be dynamically attached and detached as
|
// Find the Fragment if it was already added from a restored instance state.
|
||||||
// about:home is shown. Adding/removing the fragment is not synchronous,
|
mAboutHome = (AboutHome) getSupportFragmentManager().findFragmentByTag(ABOUTHOME_TAG);
|
||||||
// so we can't use Fragment#isVisible() to determine whether the
|
|
||||||
// about:home is shown. Instead, we use Fragment#getUserVisibleHint()
|
if (mAboutHome == null) {
|
||||||
// with the hint we set ourselves.
|
// AboutHome will be dynamically attached and detached as
|
||||||
mAboutHome = AboutHome.newInstance();
|
// about:home is shown. Adding/removing the fragment is not synchronous,
|
||||||
mAboutHome.setUserVisibleHint(false);
|
// so we can't use Fragment#isVisible() to determine whether the
|
||||||
|
// about:home is shown. Instead, we use Fragment#getUserVisibleHint()
|
||||||
|
// with the hint we set ourselves.
|
||||||
|
mAboutHome = AboutHome.newInstance();
|
||||||
|
mAboutHome.setUserVisibleHint(false);
|
||||||
|
}
|
||||||
|
|
||||||
mBrowserToolbar = new BrowserToolbar(this);
|
mBrowserToolbar = new BrowserToolbar(this);
|
||||||
mBrowserToolbar.from(actionBar);
|
mBrowserToolbar.from(actionBar);
|
||||||
@ -1092,7 +1101,7 @@ abstract public class BrowserApp extends GeckoApp
|
|||||||
// it can't be used between the Activity's onSaveInstanceState() and
|
// it can't be used between the Activity's onSaveInstanceState() and
|
||||||
// onResume().
|
// onResume().
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.add(R.id.gecko_layout, mAboutHome).commitAllowingStateLoss();
|
.add(R.id.gecko_layout, mAboutHome, ABOUTHOME_TAG).commitAllowingStateLoss();
|
||||||
mAboutHome.setUserVisibleHint(true);
|
mAboutHome.setUserVisibleHint(true);
|
||||||
|
|
||||||
mBrowserToolbar.setNextFocusDownId(R.id.abouthome_content);
|
mBrowserToolbar.setNextFocusDownId(R.id.abouthome_content);
|
||||||
|
Loading…
Reference in New Issue
Block a user