This will ensure the onPause method of removed fragment is called before onResume of the new one

This commit is contained in:
Sylvain Berfini 2018-02-15 18:00:01 +01:00
parent 128deb8791
commit 3e38e98384
6 changed files with 22 additions and 1 deletions

View file

@ -486,6 +486,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
}
}
Compatibility.setFragmentTransactionReorderingAllowed(transaction, false);
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
transaction.commitAllowingStateLoss();
fm.executePendingTransactions();

View file

@ -110,6 +110,9 @@ public class ChatRoomsAdapter extends ListSelectionAdapter {
}
public void clear() {
for (ChatRoom room : mRooms) {
room.setListener(null);
}
mRooms.clear();
}

View file

@ -3,6 +3,7 @@ package org.linphone.compatibility;
import org.linphone.R;
import android.annotation.TargetApi;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
@ -142,4 +143,8 @@ public class ApiSixteenPlus {
public static void startService(Context context, Intent intent) {
context.startService(intent);
}
public static void setFragmentTransactionReorderingAllowed(FragmentTransaction transaction, boolean allowed) {
}
}

View file

@ -2,6 +2,7 @@ package org.linphone.compatibility;
import android.annotation.TargetApi;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@ -180,4 +181,8 @@ public class ApiTwentySixPlus {
public static void startService(Context context, Intent intent) {
context.startForegroundService(intent);
}
public static void setFragmentTransactionReorderingAllowed(FragmentTransaction transaction, boolean allowed) {
transaction.setReorderingAllowed(allowed);
}
}

View file

@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import org.linphone.mediastream.Version;
import android.app.AlarmManager;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
@ -163,4 +164,10 @@ public class Compatibility {
ApiSixteenPlus.startService(context, intent);
}
}
public static void setFragmentTransactionReorderingAllowed(FragmentTransaction transaction, boolean allowed) {
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
ApiTwentySixPlus.setFragmentTransactionReorderingAllowed(transaction, allowed);
}
}
}