Note that there are some explanatory texts on larger screens.

plurals
  1. POCall startActivityForResult from Fragment doesn't call onActivityResult
    primarykey
    data
    text
    <p>I have a <code>DialogActivity</code> which is called from a <code>Fragment</code> for show a custom <code>Dialog</code> with two image buttons.</p> <p>In <code>DialogActivity.onCreate</code></p> <pre><code>final Dialog dialog = new Dialog(this, R.style.DialogTheme); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_pause); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.show(); </code></pre> <p>In <code>DialogActivity.onClick</code></p> <pre><code> @Override public void onClick(View v) { Log.d(LOGTAG, "onClick CONTINUE"); Intent resultData = new Intent(); resultData.putExtra("TEST", "return data"); setResult(666, resultData); dialog.cancel(); } </code></pre> <p>In Fragment that calls <code>startActivityForResult</code>:</p> <pre><code>Intent dialogActivityIntent = new Intent(getActivity(), DialogActivity.class); startActivityForResult(dialogActivityIntent, 999); </code></pre> <p>In <code>Activity</code> and <code>Fragment</code> that calls <code>startActivityForResult</code>:</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } </code></pre> <p>When I click the button I only get the dialog cancel and shows the background activity (fragment).</p> <p>There isn't any call to <code>onActivityResult</code>, <code>onResume</code>, ... in the <code>Fragment</code> or the <code>Activity</code> contains the <code>Fragment</code>.</p> <h2>Things I tried:</h2> <p>To implement <code>onActivityResult</code> in both, <code>Fragment</code> and <code>Activity</code> that contains my <code>Fragment</code>.</p> <h2>Things to know:</h2> <p>I set the attribute <code>noHistory=true</code> in every <code>Activity</code> I have.</p> <p>If I do <code>finish()</code> in <code>onClick</code> the <code>Activity/Fragment</code> that calls <code>DialogActivity</code> is closed too, and the application return to the before <code>Activity</code>.</p> <p><strong>This may be the problem, I DON'T call <code>finish()</code> ... but if I call <code>finish()</code>, it exits to another <code>Activity</code>, not the <code>Activity</code> that calls <code>startActivityForResult</code>.</strong></p> <h2>Links I checked:</h2> <p><a href="https://stackoverflow.com/questions/10867495/startactivityforresult-dont-call-to-onactivityresultint-requestcode-int-resu">startActivityForResult() dont call to onActivityResult(int requestCode, int resultCode, Intent data)?</a></p> <p><a href="https://stackoverflow.com/questions/13017281/cannot-get-to-trigger-onactivityresult-android">Cannot get to trigger onActivityResult() android?</a></p> <p><a href="https://stackoverflow.com/questions/7645489/startactivityforresult-doesnt-seem-to-call-onactivityresult">startActivityForResult doesn&#39;t seem to call onActivityResult</a></p> <p><a href="https://stackoverflow.com/questions/5302085/onactivityresult-never-called">onActivityResult never called</a></p> <p><a href="https://stackoverflow.com/questions/7812120/android-onactivityresult-never-called">Android onActivityResult NEVER called</a></p> <p><a href="https://stackoverflow.com/questions/8839434/onactivityresult-not-called-when-activity-started-from-fragment">onActivityResult() not called when Activity started from Fragment</a></p> <hr> <p>I hope everything is clearly explained ^^.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload