From 61013ca2d0b12868059cd59900a0cbf2ac1362e2 Mon Sep 17 00:00:00 2001 From: alexzatsepin Date: Thu, 10 Sep 2020 18:07:04 +0300 Subject: [PATCH] [android] Improved getting the fragment manager whent application is recovering after stopping by system. In some cases (tap fragments are in search) fragment manager of activity is not equal the fragment manager of fragment, so the fragment manager must be obtained always from fragment --- android/src/com/mapswithme/util/Utils.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java index 0c56c1e1d7..3ca874b287 100644 --- a/android/src/com/mapswithme/util/Utils.java +++ b/android/src/com/mapswithme/util/Utils.java @@ -28,9 +28,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NavUtils; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import com.mapswithme.maps.BuildConfig; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; @@ -725,13 +725,14 @@ public class Utils public static void detachFragmentIfCoreNotInitialized(@NonNull Context context, @NonNull Fragment fragment) { - if (context instanceof AppCompatActivity && !MwmApplication.get().arePlatformAndCoreInitialized()) - { - ((AppCompatActivity)context).getSupportFragmentManager() - .beginTransaction() - .detach(fragment) - .commit(); - } + if (MwmApplication.from(context).arePlatformAndCoreInitialized()) + return; + + FragmentManager manager = fragment.getFragmentManager(); + if (manager == null) + return; + + manager.beginTransaction().detach(fragment).commit(); } public static String capitalize(@Nullable String src)