Fix huge fragment leak when switching between tabs

This commit is contained in:
Sylvain Berfini 2016-05-11 10:01:33 +02:00
parent a90fa14b7f
commit 35a233462d

View file

@ -437,7 +437,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
FragmentTransaction transaction = getFragmentManager().beginTransaction(); FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { /*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
if (newFragmentType.isRightOf(currentFragment)) { if (newFragmentType.isRightOf(currentFragment)) {
@ -454,14 +455,19 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
}*/ }*/
if (newFragmentType != FragmentsAvailable.DIALER if (newFragmentType != FragmentsAvailable.DIALER
|| newFragmentType != FragmentsAvailable.CONTACTS_LIST && newFragmentType != FragmentsAvailable.CONTACTS_LIST
|| newFragmentType != FragmentsAvailable.CHAT_LIST && newFragmentType != FragmentsAvailable.CHAT_LIST
|| newFragmentType != FragmentsAvailable.HISTORY_LIST) { && newFragmentType != FragmentsAvailable.HISTORY_LIST) {
transaction.addToBackStack(newFragmentType.toString()); transaction.addToBackStack(newFragmentType.toString());
} else {
while (fm.getBackStackEntryCount() > 0) {
fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} }
}
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString()); transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions(); fm.executePendingTransactions();
currentFragment = newFragmentType; currentFragment = newFragmentType;
} }