ClassCastException: LinkedHashMap can't be cast to X
When using
by lazy{X}
? I think this is the second time, though haven't had it in a while. Code:
class MyFragment : Fragment() {
private val foo by lazy { MyDialogFragment(params) }
fun myFun() {
foo.show()
}
}
👀 2
t
tseisel
04/08/2022, 7:41 PM
Keeping an instance of
DialogFragment
as a class variable of another fragment feels like a memory leak to me. That may be the cause of your problem.
l
lam bui
04/09/2022, 3:37 AM
I think i want week reference, but if fragment is destroyed then it will error.
t
tseisel
04/09/2022, 8:36 AM
When shown, a
DialogFragment
is recorded in the fragment manager, you should not need to keep an explicit reference to it. You can retrieve a fragment from the fragment manager given its tag