The closest existing question I can find regarding this is Android Studio 3.0 lint warnings for references to activity, but it does not help.
Using AndroidStudio 3.0.1, I have a DialogFragment where I do this usual stuff:
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
...
I have a lint warning moaning at me that Argument 'getActivity()' might be null.
I understand why getActivity() may be null, and I understand how the lint inspection knows this (from the @Nullable annotation).
My question is: It's all very well and good that getActivity() may be null, but practically how am I supposed to deal with this gracefully and tidily? onCreateDialog must return a Dialog (because of the superclass' @Nullable annotation) so I must have the Activity context to create it.
I could assume that onCreateDialog will never be called if the DialogFragment isn't attached to an Activity, but still - how do I address the untidy lint warning?