how to startActivityForResult() in a dialog to receive result in fragment.onActivityResult

2k views Asked by At

I have a Fragment in which I call this.startActivityForResult(), the result arrives in this Fragment's onActivityResult() method and everthing works fine.

When I open a new Dialog in the same Fragment, how do I call startActivityForResult() in the Dialog to receive the result in the Fragment's onActivityResult() method as well?

getOwnerActivity().startActivityForResult(intent, NOTIFY_CODE); // doesn't work

Tried to send the Fragment's (this) to the dialog but I can't figure that out either.

- ..any help is highly appreciated!

EDIT: Code for opening the dialog

       btnNotify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {                
                NotificationDialog ndialog = new NotificationDialog(v.getContext());
                ndialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                ndialog.setDialogResult(new NotificationDialog.OnMyDialogResult() {
                    @Override
                    public void finish(int dur) {
                        notifyDuration = dur;
                    }
                });
                ndialog.show();
        }

// -- in the Dialog I want to call this

public void openNotifySel() {
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getOwnerActivity().getResources().getString(R.string.label_dialog_notify));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);

??????????????.startActivityForResult(intent, NOTIFY_CODE);
        }
1

There are 1 answers

6
aysonje On

Have you tried MyFragmentName.this.startActivityForResult(intent, NOTIFY_CODE);?