Has anyone ever gotten a `ClassCastException: Link...
# android
s
Has anyone ever gotten a
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
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
I think i want week reference, but if fragment is destroyed then it will error.
t
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