title: AudioFocusChangeListener cannot listen
body: <p>I encounter a problem using the AudioFocusChangeListener, but still cannot listen to the audio focus change. Could someone help me find the reasons? Here is what I do:</p>
  
  <ol>
  <li><p>In my FM app, when FM starts in startFM, I place <code>requestAudioFocus()</code> to get resources:</p>
  
  <pre><code>int result = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_FM,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
  if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
      Log.d(LOGTAG, "Successfull to request audioFocus listener");
  } else {
      Log.d(LOGTAG, "Failure to request focus listener");
  }
  </code></pre></li>
  <li><p>When quitting the App in <code>onDestroy()</code>, I used <code>abandonAudioFocus()</code> to release resouces.</p></li>
  <li><p>The member variable <code>mAudioFocusListener</code> is as follows:</p>
  
  <pre><code>private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() {
  public void onAudioFocusChange(int focusChange) {
      switch (focusChange) {
          case AudioManager.AUDIOFOCUS_LOSS:
              Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS, turning FM off");
  
              if (isFmOn()) {
                  fmOff();
              }
              break;
          case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
              Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
  
              if (isFmOn()) {
                  Log.d(LOGTAG, "AudioFocus: FM is on, turning off");
                  mute();
                  stopFM();
              }
              break;
          case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
              Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS_TRANSIENT");
  
              if (isFmOn()) {
                  Log.d(LOGTAG, "AudioFocus: FM is on, turning off");
                  mute();
                  stopFM();
              }
              break;
          case AudioManager.AUDIOFOCUS_GAIN:
              Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_GAIN");
  
              if (isFmOn()) {
                  Log.d(LOGTAG, "AudioFocus: FM is off, turning back on");
                  unMute();
                  startFM();
              }
              break;
          default:
              Log.e(LOGTAG, "Unknown audio focus change code " + focusChange);
      }
  }
  };
  </code></pre></li>
  <li><p>According to the log, it prints "Successfull to request audioFocus listener", but doesn't print any <code>AudioForcus</code> change log when alarm is on or other audio-changed events. Could anyone figure out what is wrong with it? </p></li>
  <li><p>On the other hand, I place log in AudioService.java and AudioManger.java, where in AudioService.java, requestAudioFocus():
   if (!mFocusStack.empty() &amp;&amp; (mFocusStack.peek().mFocusDispatcher != null)) {  </p>
  
  <pre><code>       try {  
  
              mFocusStack.peek().mFocusDispatcher.dispatchAudioFocusChange(  
  
                       -1 * focusChangeHint, // loss and gain codes are inverse of each other  
  
                       mFocusStack.peek().mClientId);  // This doesn't excute
  
          } catch (RemoteException e) {  
  
              Log.e(TAG, " Failure to signal loss of focus due to "+ e);  
              e.printStackTrace();  
  
           }  
  
       }  
  </code></pre></li>
  <li><p>in AudioManager.java, Here doesn't excute either:
      private IAudioFocusDispatcher mAudioFocusDispatcher = new IAudioFocusDispatcher.Stub() {  </p>
  
  <pre><code>public void dispatchAudioFocusChange(int focusChange, String id) {  
  
      Message m = mAudioFocusEventHandlerDelegate.getHandler().obtainMessage(focusChange, id);  
  
       mAudioFocusEventHandlerDelegate.getHandler().sendMessage(m);  
  
   }  
  </code></pre></li>
  </ol>
  
  <p>That's all my question. Could anybody tell me why this listener cannot listen to alarm events and other audiofocus-changed events? By the way, how could I successfully listen to the events? Maybe I missed some step or used a incorrect way? Many thanks.</p>