This happens because of how the DialogFragment is created.
If you use onCreateDialog()
than a slightly different lifecycle is used for this type of Fragment. The onCreateView()
will not be used, thus the viewLifecycleOwner
for this Fragment won’t be initialized.
As a workaround for this, you can use the Fragment instance as the owner for the observer:
.observe(this, Observer {...}
. Although you will get a warning for using this
instead of the viewLifecycleOwner
.