title: App crashes when recorder is supposed to stop
body: <p>I have an app uploaded on google play. <a href="https://play.google.com/store/apps/details?id=com.whizzappseasyvoicenotepad" rel="noreferrer">This is the link.</a></p>
  
  <p>It hasn't been tested on many devices yet so errors are pretty common. A user messaged me today saying that the app crashes if the togglebutton is turned ON and the button is only pressed, not held. </p>
  
  <p>This is the logcat file that he sent me:</p>
  
  <pre><code>E/MessageQueue-JNI(31135): java.lang.RuntimeException: stop failed.
  E/MessageQueue-JNI(31135): at android.media.MediaRecorder.stop(Native Method)
  E/MessageQueue-JNI(31135): at com.whizzappseasyvoicenotepad.MainActivity.stopRecording(MainActivity.java:183)
  </code></pre>
  
  <p>Quote:</p>
  
  <blockquote>
    <p>App doesn't always crash. Sometimes it does, sometimes it doesn't. It only happens when the togglebutton is ON. If I touch and hold the button it works fine but if I only touch it for a moment it crashes. I'm using Xperia S 4.1.2</p>
  </blockquote>
  
  <p>I tried this on my phone, I only touched the button instead of holding it and it worked perfectly fine, I don't know why this is happening on his phone.</p>
  
  <p>This is the code for onTouchListener:</p>
  
  <pre><code>recBtn.setOnTouchListener(new OnTouchListener(){
  
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  if (event.getAction() == MotionEvent.ACTION_DOWN)
                  {
                      startRecording();
                  }
                  else if (event.getAction() == MotionEvent.ACTION_UP)
                  {
                      stopRecording();
                      nameAlert();
                  }
              return true;
              }
          });
  </code></pre>
  
  <p>And the logcat says the problem occurs when stopRecording is called, so here is the stopRecording method:</p>
  
  <pre><code>public void stopRecording() {
      final ImageButton recBtn = (ImageButton) findViewById(com.whizzappseasyvoicenotepad.R.id.recButton);
      final ToggleButton tBtn = (ToggleButton) findViewById(R.id.tBtn1);
      if (null != recorder) {
          recorder.stop();
          recorder.reset();
          recorder.release(); 
          recorder = null;
  
          recBtn.setImageResource(com.whizzappseasyvoicenotepad.R.drawable.record_btn);
          stopTimer();
          tBtn.setEnabled(true);
      }
  }
  </code></pre>
  
  <p>I'm guessing that the problem is that he only touches the button for a moment, so before startRecording is completely called, the stopRecoring is already called so it crashes because startRecording wasn't even completely intiated yet. If that's the case, how can I fix it? If it isn't the case, what's wrong then? And why would an error like this appear on another phone but not mine?</p>