@Override protected void onPause() { super.onPause(); if (recordPressed) { task.stopCapture(); } }
public void processRecordingTask() { if (!recordPressed) { // start name dialog final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); final View dialogView = inflater.inflate(R.layout.name_dialog, null); dialogBuilder.setView(dialogView); final String[] mName = new String[1]; final EditText edt = (EditText) dialogView.findViewById(R.id.name_edt); dialogBuilder.setTitle("Name your noise"); dialogBuilder.setMessage("Please enter a name"); dialogBuilder.setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing - for older versions of android } }); final AlertDialog noiseNameDialog = dialogBuilder.create(); noiseNameDialog.show(); // the listener in which we can control whenever we dismiss the dialog or not. noiseNameDialog .getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (edt.getText().toString().isEmpty()) { Snackbar.make(snackbarView, "Please enter a name !", Snackbar.LENGTH_SHORT) .show(); } else { recordPressed = true; mName[0] = edt.getText().toString(); task = new RecordTask( title, titleText, recordStartImg, chronometer, recordBtn, getApplicationContext(), mName[0]); task.execute(); noiseNameDialog.dismiss(); } } }); } else { try { task.stopCapture(); recordPressed = false; } catch (RuntimeException e) { e.printStackTrace(); } } }