title: How to make a button play a sound as it launches another activity when pressed?
body: <p>Current code:</p>
  
  <pre><code>   MediaPlayer mp;
  
      button1=(ImageButton)findViewById(R.id.button1);
      button1.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent i = new Intent(getApplicationContext(), Activity1.class);
              startActivity(i);
          }
  
      });
  </code></pre>
  
  <p>So how would a button start a new activity and play a sound while doing so?</p>
  
  <p>What I've tried: various methods like playSound( ); in the method.</p>
  
  <p>It only plays the default android sound. I want a specific sound stored in the raw directory. So when the button get's pressed it launches both the intent to launch the activity as well as the specific sound.</p>
  
  <p>Error:</p>
  
  <p>When I try to put MediaPlayer mp; above the button, it states variable mp is already defined. I just need someone to append the activity launch code so that it will play the sound as well.</p>