title: Passing soundpool to multiple activities in Android
body: <p>Basically, in a short explanation, I am making a sound board. Once I run the initial activity, it adds all sound clips to the soundpool. I then have two other activities that are to organize the sound clips, and I would like to use the previously loaded soundpool so that there isn't move load time when switching between activities. I am fairly new to this Android coding, so please make things in simple terms!</p>
  
  <p>EDIT: Also, does anybody know how to stop the playback on a second button click? Not as in clicking a different button, I understand that, but if the same button is clicked, it will stop it?</p>
  
  <p>My main activity:</p>
  
  <p><code>private SoundManager mSoundManager;</code></p>
  
  <pre><code>/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);      
      setContentView(R.layout.main);
      mSoundManager = new SoundManager();
      mSoundManager.initSounds(getBaseContext());
      mSoundManager.addSound(0, R.raw.stop_playing);
      mSoundManager.addSound(1, R.raw.sound1);
      mSoundManager.addSound(2, R.raw.sound2);
      mSoundManager.addSound(3, R.raw.sound3);
  </code></pre>
  
  <p>Dealing with soundpool stuff:</p>
  
  <p><code>public void initSounds(Context theContext) { 
           mContext = theContext;
           mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); 
           mSoundPoolMap = new HashMap&lt;Integer, Integer&gt;(); 
           mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);<br>
      }</code></p>
  
  <pre><code>public void addSound(int Index,int SoundID)
  {
      mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));
  
  }
  
  public void pauseSound(){
      mSoundPool.autoPause();
  }
  
  public void stopSound(){
      mSoundPool.stop(playingNumber);
  }
  
  
  public int playSound(int index) { 
  
       int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
       int soundId = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
       mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); 
       playingNumber = index;
       return playingNumber;
  }
  </code></pre>
  
  <p>}</p>