title: Refactoring code with static listeners
body: <p>After some debugging I found the following thing in existing <em>production</em> code:</p>
  
  <pre><code>public class SomeTTS {
      private static TTSSpeechListener mSpeechListener;
      private static TTSBreakListener mBreakListener;
      // more static (!!!) listeners
      private String mPath;
  
      public TTS(String path, TTSSpeechListener speechListener)
              throws RuntimeException {
          // ...
          mSpeechListener = speechListener;
          mBreakListener = null;
          // more listeners set to null
          // ...
      }
      // called from NATIVE code that I cannot change
      private static void onReceiveSpeechData(byte[] samples) {
          mSpeechListener.onSpeechData(samples);
      }
      // ...
  }
  </code></pre>
  
  <p>The class is a wrapper for a native library (Android, NDK, JNI). I have no access to the native library source. (You, of course, see the problem: after I create a 2nd instance of <code>SomeTTS</code>, the 1st instance does not work anymore.) I am a bit shocked: I would not expect such bugs from anyone but a schoolboy. Probably they were using child labor. Or, more likely, someone could not explain the difference between a demo and production code to his manager.</p>
  
  <p>Anyway, I have to make it work. I have some thoughts, but what I can propose at the moment is far from perfect. Any ideas how to refactor it?</p>