On showing dialog i get “Can not perform this action after onSaveInstanceState”

前端 未结 17 1086
甜味超标
甜味超标 2020-11-29 18:37

Some users are reporting, if they use the quick action in the notification bar, they are getting a force close.

I show a quick action in the notification who calls t

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 19:11

    If you override show() function, don't do this:

    override fun show(manager: FragmentManager, tag: String?) {
        // mDismissed = false; is removed -> lead to wrong state
        // mShownByMe = true; is removed -> lead to wrong state
        val ft = manager.beginTransaction()
        ft.add(this, tag)
        ft.commitAllowingStateLoss()
    }
    

    It maybe lead to wrong state of dialog

    Just do:

    override fun show(manager: FragmentManager, tag: String?) {
        try {
            super.show(manager, tag)
        } catch (e: Exception) {
            val ft = manager.beginTransaction()
            ft.add(this, tag)
            ft.commitAllowingStateLoss()
        }
    }
    

提交回复
热议问题