null check for target fragment in dialog
This commit is contained in:
parent
e4ba7c293c
commit
dbdfef7b21
1 changed files with 9 additions and 2 deletions
|
@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -64,14 +65,20 @@ public class DialogHelper extends DialogFragment implements TrackbookKeys {
|
|||
dialogBuilder.setPositiveButton(positiveButton,
|
||||
new DialogInterface.OnClickListener() {
|
||||
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,
|
||||
new DialogInterface.OnClickListener() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue