title: Muting streams in Android
body: <p>I've built a small app that mutes/unmute the music stream using the class <code>AudioManager</code>.
  In fact, it works until I close the application. i.e. I've muted the sream, I close the app, I restart the app and the button doesn't unmute the stream any more. I've searched in the net but no one seems to have met this problem.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class ControlloVolume extends Activity {
  ToggleButton tb_mute;
  Button btn_mute;
  AudioManager mAudioManager;
  boolean mute;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_controllo_volume);
  
      tb_mute = (ToggleButton) findViewById(R.id.tb_mute);
      btn_mute = (Button) findViewById(R.id.btn_mute);
      mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  
      if(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)==0){
          mute = true;
          tb_mute.setChecked(mute);
      }else{
          mute = false;
          tb_mute.setChecked(mute);
      }
  
      }
  
  public void onButtonClicked(View view){
      if(!mute){
          mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
          tb_mute.setChecked(true);
          mute = true;
      }else{
          mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
          tb_mute.setChecked(false);
          mute = false;
      }
  }
  </code></pre>