0

I am developing a new app and when I logged in using email and password it is crashing giving an error below

java.lang.IllegalArgumentException: View=DecorView@ff5fb5d[MainActivity] not attached to window manager at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:479) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:388) at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:128) at android.app.Dialog.dismissDialog(Dialog.java:610) at android.app.Dialog.dismiss(Dialog.java:593) at com.empowered.healo.ui.views.CustomAlertDialog.access$dismiss$s-1404601997(CustomAlertDialog.kt:23) at com.empowered.healo.ui.views.CustomAlertDialog$dismiss$$inlined$let$lambda$1.onAnimationEnd(CustomAlertDialog.kt:107) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1149) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1309) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146) at android.animation.AnimationHandler.-wrap2(AnimationHandler.java) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:925) at android.view.Choreographer.doCallbacks(Choreographer.java:702) at android.view.Choreographer.doFrame(Choreographer.java:635) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

I have followed this link

View not attached to window manager crash

below my CustomAlertDialog.kt

class CustomAlertDialog(context: Context) : AlertDialog(context, R.style.AppTheme_FullScreenDialogStyle), CustomAlertDialogBuilder.CustomDialogInterface {
    var dismissListener: CustomAlertDialogBuilder.OnDismissListener? = null
    private var cancelableDialog = true
    var alertDialogInfo = CustomAlertDialogBuilder.AlertDialogInfo()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.custom_dialog)
        if (cancelableDialog) {
            rootDialogLayout.setOnClickListener { dismiss() }
        }

        btnPositive.visibility = if (alertDialogInfo.positiveText != null) View.VISIBLE else View.GONE
        btnPositive.text = alertDialogInfo.positiveText

        btnNegative.visibility = if (alertDialogInfo.negativeText != null) View.VISIBLE else View.GONE
        btnNegative.text = alertDialogInfo.negativeText

        btnNeutral.visibility = if (alertDialogInfo.neutralText != null) View.VISIBLE else View.GONE
        btnNeutral.text = alertDialogInfo.neutralText

        dialogTitle.visibility = if (alertDialogInfo.titleText != null) View.VISIBLE else View.GONE
        dialogTitle.text = alertDialogInfo.titleText

        alertDialogInfo.textColor?.let {
            btnPositive.setTextColor(it)
            btnNegative.setTextColor(it)
            btnNeutral.setTextColor(it)
            message?.setTextColor(it)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                buttonsControl?.dividerDrawable?.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.MULTIPLY)
            }
        }

        message?.text = this.alertDialogInfo.message

        alertDialogInfo.background?.let {
            backgroundImage.setImageResource(it)
        }
        btnPositive.setOnClickListener { alertDialogInfo.onPositiveClickListener?.onClick(this) }
        btnNeutral.setOnClickListener { alertDialogInfo.onNeutralClickListener?.onClick(this) }
        btnNegative.setOnClickListener { alertDialogInfo.onNegativeClickListener?.onClick(this) }
    }

    override fun setCancelable(flag: Boolean) {
        super.setCancelable(flag)
        cancelableDialog = flag
    }


    override fun onStart() {
        super.onStart()
        val animationSet = AnimatorSet()
        val decorView = this
                .window
                .decorView
        decorView.setBackgroundColor(Color.TRANSPARENT)
        backgroundImage?.let {
            val titleAnimation = ObjectAnimator.ofFloat(dialogTitle, View.TRANSLATION_Y, -50.dp.toFloat(), 0f)
            val imageAnimation = ObjectAnimator.ofFloat(it, View.SCALE_X, 0f, 1f)
            val startAnimation = ObjectAnimator.ofFloat(decorView, View.ALPHA, 0f, 1f)
            animationSet.playTogether(titleAnimation, imageAnimation, startAnimation)
        }

        animationSet.duration = 350
        animationSet.interpolator = LinearInterpolator()
        animationSet.start()

    }

    override fun dismiss() {
        val animationSet = AnimatorSet()
        val decorView = this
                .window
                .decorView

        backgroundImage?.let {
            val imageAnimation = ObjectAnimator.ofFloat(it, View.SCALE_X, 1f, 0f)
            val titleAnimation = ObjectAnimator.ofFloat(dialogTitle, View.TRANSLATION_Y, 0f, -50.dp.toFloat())
            val endAnimation = ObjectAnimator.ofFloat(decorView, View.ALPHA, 1.0f, 0.0f)

            val listeners = object : AnimationListener() {
                override fun onAnimationEnd(animation: Animator?) {
                    super@CustomAlertDialog.dismiss()
                    dismissListener?.onDismiss()
                }
            }
            imageAnimation.addListener(listeners)
            animationSet.playTogether(titleAnimation, endAnimation, imageAnimation)
        }

        animationSet.duration = 350
        animationSet.interpolator = LinearInterpolator()
        animationSet.start()
    }

    override fun dismiss(callDismissListener: Boolean) {
        if (!callDismissListener)
            setOnDismissListener { }
        dismiss()
    }

    override fun dismiss(onDismissListener: CustomAlertDialogBuilder.OnDismissListener) {
        dismissListener = onDismissListener
        dismiss()
    } }
Anmol
  • 8,110
  • 9
  • 38
  • 63
  • can you point line where your are getting the error? – Anmol Dec 26 '18 at 17:49
  • `if (cancelableDialog) { rootDialogLayout.setOnClickListener { post{ dismiss() } } }` . try adding this code to `onStart()` instead of `onCreate()` add post Command so that the dismiss will be called when all mainThread queue is done this might fix the error.if it work's i will post it as an answer – Anmol Dec 26 '18 at 18:03

0 Answers0