Note that there are some explanatory texts on larger screens.

plurals
  1. POSubActivity inside another SubActibity
    text
    copied!<p>I am working on a mediaPlayer app for which I am using ListViews for my playlist. I have the main activity which has the mediaPlayer and when user clicks on the the playlist button, ArtistActivity is launch from which the user can launch SongActivity. I have looked at numerous tutorials and examples but for some reason SongActivity is passing "0" back to the main activity and playing the first track in the ArrayList with the songs URLs. Any help would be much appreciated. Please help. Thank you. </p> <p><em><strong>MainActivity:</em></strong></p> <pre><code> btnPlaylist.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { Intent i = new Intent(getApplicationContext(),ArtistActivity.class); startActivityForResult(i, 100); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == 50) { currentSongIndex = data.getExtras().getInt("songIndexArtist"); songIndex = currentSongIndex; // play selected song playSong(currentSongIndex); // Displaying Song title String songTitle = songsList.get(currentSongIndex).get("songTitle"); songTitleLabel.setText(songTitle); } </code></pre> <p><em><strong>ArtistActivity:</em></strong></p> <pre><code>lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { //int artistIndex = position; // Starting new intent Intent in2 = new Intent(getApplicationContext(),SongActivity.class); startActivityForResult(in2,100); setResult(100,in2); in2.putExtra("songIndexArtist", songIndexArtist); finish(); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == 50) { songIndexArtist = data.getExtras().getInt("songIndex"); } } </code></pre> <p><em><strong>SongActivity:</em></strong></p> <pre><code>lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "DOWNLOADING, PLEASE WAIT", Toast.LENGTH_LONG).show(); // getting listitem index int songIndex = position; // Starting new intent Intent in3 = new Intent(getApplicationContext(), AndroidBuildingMusicPlayerActivity.class); // Sending songIndex to PlayerActivity in3.putExtra("songIndex", songIndex); setResult(50,in3); // Closing PlayListView finish(); } }); } </code></pre>
 

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