From 192b72200c3d2f32d238e9b1ff76bc9507d22077 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 21 Jul 2020 09:40:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseDialogFragment.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt index 7e016521a..093d5fbed 100644 --- a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt @@ -3,6 +3,7 @@ package io.legado.app.base import android.os.Bundle import android.view.View import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ThemeStore import kotlinx.coroutines.CoroutineScope @@ -10,6 +11,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlin.coroutines.CoroutineContext + abstract class BaseDialogFragment : DialogFragment(), CoroutineScope { override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main @@ -29,6 +31,17 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope { abstract fun onFragmentCreated(view: View, savedInstanceState: Bundle?) + override fun show(manager: FragmentManager, tag: String?) { + try { + //在每个add事务前增加一个remove事务,防止连续的add + manager.beginTransaction().remove(this).commit() + super.show(manager, tag) + } catch (e: Exception) { + //同一实例使用不同的tag会异常,这里捕获一下 + e.printStackTrace() + } + } + override fun onDestroy() { super.onDestroy() job.cancel()