title: Android - Making SoundPool a global class? (Available to all other classes)
body: <p>So basically, I'm creating a game on a SurfaceView and I have these classes on my main CustomView:</p>
  
  <pre>private TitleScreen titleScreen;<br>private GameScreen gameScreen;<br>private PauseScreen pauseScreen;<br>private GameOverScreen gameOverScreen;
  </pre>
  
  <p>Each of these classes have a <code>draw(Canvas canvas)</code> method, and is called when the user goes to another screen. But the thing is, I have a <code>SoundPlayer</code> class that includes all of my sound effects using SoundPool. It will be used on all these classes. Is there actually a way that the SoundPlayer only loads once, then is available throughout these classes? Or do I have to call <code>release()</code> and recall the constructor everytime I switch? Thanks in advance. :D</p>
  
  <p>UPDATE (SOLVED):</p>
  
  <p>So here's what I did. I created an instance of my SoundPlayer class:</p>
  
  <pre>
  public class SoundPlayerInstance {<br>    private static SoundPlayer soundPlayerInstance;<br>    private SoundPlayerInstance(){}<br><br>    public static void createInstance(Context context){<br>        soundPlayerInstance = new SoundPlayer(context);<br>    }<br><br>    public static SoundPlayer getInstance(){<br>        return soundPlayerInstance;<br>    }<br>}
  </pre>
  
  <p>On my main view, before I do anything, I call this in my constructor:</p>
  
  <p><code>SoundPlayerInstance.createInstance();</code></p>
  
  <p>Then, on any of my classes, I can just call it to play the sound:</p>
  
  <p><code>SoundPlayerInstance.getInstance().playSound();</code></p>
  
  <p>I think this will be useful not only for situations like these, but it can also be useful for developers (like me) that want to instantiate a class that is available throughout all other classes. Thanks to system32 for answering my question. :)</p>