title: Android app: creating a mute button
body: <p>I'm trying to create a mute button for my game, through a toggle button. I have an activity called "Settings" where my ToggleButton is, and, when isChecked, i need to "delete" all the sounds in other activities (Not to set the phone's volume!). But i need help :(</p>
  
  <p>That's my Toggle Button on Settings' XML:</p>
  
  <pre><code>&lt;ToggleButton
      android:id="@+id/sound2"
      android:layout_width="250sp"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/sound"
      android:layout_marginTop="129dp"
      android:background="@drawable/mainbuttons_style"
      android:onClick="onToggleClicked"
      android:text="@string/sound2"
      android:textColor="#4a4646"
      android:textOff="Sound OFF"
      android:textOn="Sound ON"
      android:textSize="15sp" /&gt;
  </code></pre>
  
  <p>That's part of my Settings' Java file:</p>
  
  <pre><code>public void onToggleClicked(View view) {
      // Is the toggle on?
      boolean on = ((ToggleButton) view).isChecked();
  
  
      if (on) {
  
      } else {
          mediaPlayer = MediaPlayer.create(Settings.this, R.raw.twinkle);
          mediaPlayer.start();
  
      }
  
      }   
  </code></pre>
  
  <p>All sounds in the game are reproduced by a Button touch. That's an example:</p>
  
  <p>Activity1:</p>
  
  <pre><code>@Override
  public void onCreate //....
  
  ToggleButton toggle = (ToggleButton) findViewById(R.id.sound2);
  toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  if (isChecked) {
        //do nothing                     
  } else {
  
  MediaPlayer mediaPlayer = MediaPlayer.create(FirstImageLogo.this, R.raw.twinkle);
  mediaPlayer.start();
  }
    }
      });
  </code></pre>
  
  <p>But it returns null.. I've tried everything with no success. Thank you for your time!</p>