- // The public interface is used to send information back to the parent activity.
- public interface DownloadFileListener {
- void onDownloadFile(AppCompatDialogFragment dialogFragment, String downloadUrl);
- }
-
- // `downloadFileListener` is used in `onAttach()` and `onCreateDialog()`.
- private DownloadFileListener downloadFileListener;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
-
- // Check to make sure the parent activity implements the listener.
- try {
- downloadFileListener = (DownloadFileListener) context;
- } catch (ClassCastException exception) {
- throw new ClassCastException(context.toString() + " must implement DownloadFileListener.");
- }
- }
-
- @Override
- @NonNull
- // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
- @SuppressLint("InflateParams")
- public Dialog onCreateDialog(Bundle savedInstanceState) {