title: MediaRecorder : stop called in invalid state : 4
body: <p>I'm creating a call recording app, when I'm trying to stop call recording the Debug Console in java says that: "MediaRecorder stop called in an invalid state : 4" I've Googled a lot but I can't find anything that can help me! I'm already using <code>RECORD_AUDIO</code> and <code>WRITE_EXTERNAL_STORAGE</code> permissions! Here is part of my code:</p>
  
  <pre><code>private class PhoneCallListener extends PhoneStateListener {
      private boolean isPhoneCalling = false;
      @SuppressWarnings("deprecation")
      @Override
      public void onCallStateChanged(int state, final String incomingNumber) {
          // TODO Auto-generated method stub
          super.onCallStateChanged(state, incomingNumber);
          String path = Environment.getExternalStorageDirectory()+"/callrec/";
          final MediaRecorder recorder = new MediaRecorder();
          recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
          recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
          recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
          recorder.setOutputFile(path+"/TEST00000000011110.M4A");
          if (TelephonyManager.CALL_STATE_RINGING == state) {
  
          }
          if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
              isPhoneCalling = true;
              try {
                  recorder.prepare();
                  recorder.start();
              } catch (Exception e) {
              }
          }
          if (TelephonyManager.CALL_STATE_IDLE == state) {
              if (isPhoneCalling) {
                  try {
                      recorder.stop();
                      recorder.reset();
                      recorder.release();
                  } catch (Exception e) {
                      // TODO: handle exception
                  }
                  Intent i = getBaseContext().getPackageManager()
                          .getLaunchIntentForPackage(
                                  getBaseContext().getPackageName());
                  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(i);
                  isPhoneCalling = false;
              }
          }
      }
  }
  </code></pre>