executePendingTransactions before trying to access secondary_fragment
If we don’t executePendingTransactions we might still access the overview fragment while a replacement operation is in the works. This will lead to two conversationfragments opening.
This commit is contained in:
parent
581eb511b9
commit
f975b5ddac
|
@ -425,16 +425,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConversation(Conversation conversation, Bundle extras) {
|
private void openConversation(Conversation conversation, Bundle extras) {
|
||||||
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
final FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
fragmentManager.executePendingTransactions();
|
||||||
|
ConversationFragment conversationFragment = (ConversationFragment) fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
final boolean mainNeedsRefresh;
|
final boolean mainNeedsRefresh;
|
||||||
if (conversationFragment == null) {
|
if (conversationFragment == null) {
|
||||||
mainNeedsRefresh = false;
|
mainNeedsRefresh = false;
|
||||||
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
if (mainFragment instanceof ConversationFragment) {
|
if (mainFragment instanceof ConversationFragment) {
|
||||||
conversationFragment = (ConversationFragment) mainFragment;
|
conversationFragment = (ConversationFragment) mainFragment;
|
||||||
} else {
|
} else {
|
||||||
conversationFragment = new ConversationFragment();
|
conversationFragment = new ConversationFragment();
|
||||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
|
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
|
||||||
fragmentTransaction.addToBackStack(null);
|
fragmentTransaction.addToBackStack(null);
|
||||||
try {
|
try {
|
||||||
|
@ -562,17 +564,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFragments() {
|
private void initializeFragments() {
|
||||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
final FragmentManager fragmentManager = getFragmentManager();
|
||||||
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||||
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
||||||
|
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
||||||
if (mainFragment != null) {
|
if (mainFragment != null) {
|
||||||
if (binding.secondaryFragment != null) {
|
if (binding.secondaryFragment != null) {
|
||||||
if (mainFragment instanceof ConversationFragment) {
|
if (mainFragment instanceof ConversationFragment) {
|
||||||
getFragmentManager().popBackStack();
|
getFragmentManager().popBackStack();
|
||||||
transaction.remove(mainFragment);
|
transaction.remove(mainFragment);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
getFragmentManager().executePendingTransactions();
|
fragmentManager.executePendingTransactions();
|
||||||
transaction = getFragmentManager().beginTransaction();
|
transaction = fragmentManager.beginTransaction();
|
||||||
transaction.replace(R.id.secondary_fragment, mainFragment);
|
transaction.replace(R.id.secondary_fragment, mainFragment);
|
||||||
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
@ -583,7 +586,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
transaction.remove(secondaryFragment);
|
transaction.remove(secondaryFragment);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
getFragmentManager().executePendingTransactions();
|
getFragmentManager().executePendingTransactions();
|
||||||
transaction = getFragmentManager().beginTransaction();
|
transaction = fragmentManager.beginTransaction();
|
||||||
transaction.replace(R.id.main_fragment, secondaryFragment);
|
transaction.replace(R.id.main_fragment, secondaryFragment);
|
||||||
transaction.addToBackStack(null);
|
transaction.addToBackStack(null);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
|
Loading…
Reference in a new issue