Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.5K
Visualizações
Fragment not associated with a fragment manager. (Dialog Fragment)

I have a dialog fragment, and i make a class for lazy initialization. When i'm showing the dialog, it's showing like normal. but, when i'm dismissing the dialog, it crash caused by : Fragment not associated with a fragment manager.

i have tried to postDelayed dimiss too, but still crashing.

LoadingDialog.kt

class LoadingDialog(private val fm: FragmentManager) : DialogFragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        isCancelable = false
        return inflater.inflate(R.layout.dialog_loading, container, false)
    }

    fun showDialog(tag: String? = null) {
        show(fm, tag)
    }

    fun closeDialog() {
        dismiss()
    }
}

LazyDialog.kt

class LazyDialog<T : DialogFragment>(private val type: Class<T>, private val fm: FragmentManager) :
    Lazy<T> {
    private var dialog: T? = null

    override val value: T
        get() {
            return when {
                type.isAssignableFrom(LoadingDialog::class.java) -> {
                    LoadingDialog(fm).also {
                        dialog = it as T
                    } as T
                }
                else -> throw IllegalArgumentException("Unknown class : ${type.name}")
            }
        }

    override fun isInitialized(): Boolean = dialog != null
}

Extensions.kt

inline fun <reified T : DialogFragment> FragmentActivity.loadingDialog(): Lazy<T> {
    return LazyDialog(T::class.java, supportFragmentManager)
}

LoginActivity.kt

private val loadingDialog: LoadingDialog by loadingDialog()

enter image description here

over 4 years ago · Hanz Gallego
1 Respostas
Responde à pergunta

0

You may be trying to dismiss it in the onDestroy method of a fragment, that was my case at least. Move the dismiss method call to the onStop of your activity or a fragment.

over 4 years ago · Hanz Gallego Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda