null check for target fragment in dialog

This commit is contained in:
y20k 2019-03-19 08:37:28 +01:00
parent e4ba7c293c
commit dbdfef7b21

View file

@ -24,6 +24,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
/** /**
@ -64,14 +65,20 @@ public class DialogHelper extends DialogFragment implements TrackbookKeys {
dialogBuilder.setPositiveButton(positiveButton, dialogBuilder.setPositiveButton(positiveButton,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, getActivity().getIntent()); Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, getActivity().getIntent());
}
} }
} }
); );
dialogBuilder.setNegativeButton(negativeButton, dialogBuilder.setNegativeButton(negativeButton,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, getActivity().getIntent()); Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, getActivity().getIntent());
}
} }
} }
); );