I want to enforce the use of having a tag used in the show method for a DialogFragment
:
MyDialogFragment fragment = MyDialogFragment.newInstance(args);
fragment.show(getSupportFragmentManager(), MANDATORY_TAG);
Is there a way to enforce this, or throw an error from within the fragment somehow, if MANDATORY_TAG
is ""
or null
?
if (tag == null || tag.isEmpty()) {
throw new NullPointerException("Please add the Tag. Tag cannot be null or empty");
}
Edit:
try {
MyDialogFragment fragment = MyDialogFragment.newInstance(args);
fragment.show(getSupportFragmentManager(), MANDATORY_TAG);
} catch (NullPointerException e) {
e.printStackTrace();
}