Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have mixed <code>requestCode</code> and <code>resultCode</code>. <code>resultCode</code> should be one of predefined constants <code>RESULT_CANCELED</code>, <code>RESULT_OK</code>, <code>RESULT_FIRST_USER</code> etc. <code>requestCode</code> is your unique values - 50, 100, etc.</p> <p>Also the <code>requestCode</code> should be the same in the <code>startActivityForResult</code> call and in <code>onActivityResult</code> handler in the same activity.</p> <p>For example, in the <strong>SongActivity</strong> you should call:</p> <pre><code>setResult(RESULT_OK, in3); </code></pre> <p>and in the <strong>ArtistActivity</strong> you should call:</p> <pre><code>startActivityForResult(in2, 50); </code></pre> <p>because your <code>onActivityResult</code> in the <strong>ArtistActivity</strong> awaits code 50.</p> <pre><code>lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Intent in2 = new Intent(getApplicationContext(), SongActivity.class); // Starting SongActivity and wait for results with requestCode 50 startActivityForResult(in2, 50); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == 50 &amp;&amp; resultCode == RESULT_OK) { // get results from SongActivity (requestCode = 50) songIndexArtist = data.getExtras().getInt("songIndex"); // now pass the same data into MainActivity Intent result = new Intent(); result.putExtra("songIndexArtist", songIndexArtist); setResult(RESULT_OK, result); finish(); } } </code></pre> <p>Note that I replaced resultCode with requestCode.</p> <p>You should fix <strong>MainActivity</strong> in the similar way.</p> <p>Also you may possibly use <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_FORWARD_RESULT" rel="nofollow noreferrer"><code>FLAG_ACTIVITY_FORWARD_RESULT</code> flag</a>; there is a related <a href="https://stackoverflow.com/questions/9135449/how-to-return-a-result-through-multiple-activities">SO question</a> and a <a href="http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/" rel="nofollow noreferrer">good explanation of this flag</a> (among other flags). The flag is usefull if you pass results back through intermediate activities without any processing, "as is".</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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