what you need to do is transfer the selected lesson from the first activity and load the correct sound in the second one.
you can recognize which button (lesson) to play in several ways,
simple is numeric 1, 2, 3 ... each number is a lesson, or you can pass the resource identifier of the audio file and just play it in the next step, this option is better because you do not need to use the if statement in the next step to find out what is a lesson 4 index.
so we go
for the audio1 button, pass the res id of lesson 1
audio1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent audio_intent = new Intent(getApplicationContext(), AudioPopup.class); audio_intent.putExtra("lesson_res_id", R.raw.lesson1-1); startActivity(audio_intent); } });
and for the audio2 button, pass the res id of lesson 2
audio2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent audio_intent = new Intent(getApplicationContext(), AudioPopup.class); audio_intent.putExtra("lesson_res_id", R.raw.lesson2-2); startActivity(audio_intent); } });
now in the second step, get this passed value and play the audio.
int lessonResId = getIntent().getIntExtra("lesson_res_id", -100); //-100 is default, means the key 'lesson_res_id' was not found in extras bundle playAudio(lessonResId);
you can reorganize the code (if you have too many buttons) by creating a method that triggers a pop-up action and calling it from onClick the passing audio res id
private void openPopupActivity(int resId){ Intent audio_intent = new Intent(getApplicationContext(), AudioPopup.class); audio_intent.putExtra("lesson_res_id", resId); startActivity(audio_intent); }
and onClick will be
audio2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openPopupActivity(R.raw.lesson2-2); } });