如何在对话框中startActivityForResult()以在fragment.onActivityResult中接收结果

时间:2013-12-03 02:16:07

标签: android start-activity onactivityresult

我有一个片段,我在其中调用this.startActivityForResult(),结果到达此Fragment的onActivityResult()方法,并且everthing工作正常。

当我在同一个Dialog中打开一个新的Fragment时,如何在对话框中调用startActivityForResult()以便在Fragment的onActivityResult()方法中接收结果?

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

尝试将片段(this)发送到对话框,但我也无法解决这个问题。

- ..非常感谢您的帮助!

编辑:打开对话框的代码

       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();
        }

// - 在对话框中我想称之为

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 个答案:

答案 0 :(得分:0)

您是否尝试过MyFragmentName.this.startActivityForResult(intent, NOTIFY_CODE);