If I had my DialogFragment declared as an inner class I got an InstantiationException on orientation change, i.e. when instance is recreated, which says there is no public constructor, class isn’t public etc. In fact everything is public, default constructor is in place. If I just move this DialogFragment to a separate file – everything goes fine. I’m not looking for a workaround, I just want to understand why this is happening.
If I had my DialogFragment declared as an inner class I got an InstantiationException
Share
This seems to be a restriction in Java based on how
Fragmentsare created and recreated.It seems that all
Fragments have to be reinstantiated in certain situations[1], such as orientation changes (and I would guess upon initialization, depending on how theFragmentis created). This means that it will be reinstantiated from outside your outer class. However, a non-staticinner class cannot be instantiated from outside the outer class.[2] There are also other cases in which aFragmentwould need to be communicated with from outside the class.[3]