Return result to Activity from DialogFragment
<p>I am trying to do the following:</p>

<ol>
<li>Show dialog fragment from an Activity (not Fragment);</li>
<li>Retrieve result in the Activity.</li>
</ol>

<p>The problem is that onActivityResult in the Activity is not being called.</p>

<p>Here is how I am showing a DialogFragment</p>

<pre><code>DriverRatingDialogFragment dp = new DriverRatingDialogFragment();
// this solution works well in case of showing dialog from a fragment
// but I have to show it from the Activity
// dp.setTargetFragment(getSupportFragmentManager().findFragmentById(R.id.flContent), DriverRatingDialogFragment.REQUEST_CODE);
dp.show(getSupportFragmentManager(), DriverRatingDialogFragment.ARG_RATING);
</code></pre>

<p>And here is how I am trying to return result from DialogFragment:   </p>

<pre><code>    Intent intent = new Intent();

    // This solution works well in case of previously setting target Fragment,
    // but I have to return result to Activity

    // getTargetFragment().onActivityResult(
    // getTargetRequestCode(), REQUEST_CODE, intent);


    // and with this attempt App crashes
    // this.onActivityResult(REQUEST_CODE, Activity.RESULT_OK, intent);
</code></pre>

<p>here is where I want to retrieve result in the Activity, but it doesn't get called:   </p>

<pre><code>    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == DriverRatingDialogFragment.REQUEST_CODE) {
            // todo

        }
        super.onActivityResult(requestCode, resultCode, data);
    }
</code></pre>

<p>What's wrong?</p>