Dportology Dportology - 1 year ago 82
Android Question

Android DialogFragment get name of class the dialog was created from

Within my dialog fragment, I am looking to display the name of the activity from which the dialog fragment was created.

I have tried the following:


But this throws a null point exception on getClass().

Any idea of how I could the class name the dialog fragment was created from?

Answer Source

DialogFragment, as a Fragment, is always attached to activity. Hence, you do not need to call getCallingPackage. Instead, from within your dialog fragment, just call getActivity().getClass().getSimpleName()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download