private synchronized void stopRecording() {
   if (soundRecorder == null || !soundRecorder.isRecording()) {
     return;
   }
   setViewsToNotRecordingState();
   try {
     soundRecorder.stop();
     Uri uri = soundRecorder.getPath();
     setResult(Activity.RESULT_OK, new Intent(Intent.ACTION_PICK, uri));
   } catch (IOException e) {
     Log.e("CATROID", "Error recording sound.", e);
     Toast.makeText(this, R.string.soundrecorder_error, Toast.LENGTH_SHORT).show();
     setResult(Activity.RESULT_CANCELED);
   }
 }
 private synchronized void startRecording() {
   if (soundRecorder != null && soundRecorder.isRecording()) {
     return;
   }
   try {
     String recordPath =
         Utils.buildPath(
             Constants.TMP_PATH,
             getString(R.string.soundrecorder_recorded_filename) + Constants.RECORDING_EXTENTION);
     soundRecorder = new SoundRecorder(recordPath);
     soundRecorder.start();
     setViewsToRecordingState();
   } catch (IOException e) {
     Log.e("CATROID", "Error recording sound.", e);
     Toast.makeText(this, R.string.soundrecorder_error, Toast.LENGTH_SHORT).show();
   }
 }
 @Override
 public void onClick(View v) {
   if (v.getId() == R.id.recordLayout) {
     if (soundRecorder != null && soundRecorder.isRecording()) {
       stopRecording();
       finish();
     } else {
       startRecording();
     }
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_soundrecorder);

    recordLayout = (LinearLayout) findViewById(R.id.recordLayout);
    recordButton = (ImageView) findViewById(R.id.recordButton);
    recordText = (TextView) findViewById(R.id.recordText);
    recordingIndicationText = (TextView) findViewById(R.id.recording);

    recordLayout.setOnClickListener(this);

    soundRecorder = (SoundRecorder) getLastCustomNonConfigurationInstance();
    if (soundRecorder != null && soundRecorder.isRecording()) {
      setViewsToRecordingState();
    }

    Utils.checkForSdCard(this);
  }