录制多个音频语音并添加一个按钮,以便在录制后返回上一个活动。但经过多次录制并尝试返回上一页,该页面不会直接切换到上一页。如果我录制4个音频语音并尝试转到上一个点击按钮,他将4次显示同一页面并显示4个记录,再次单击显示3,再次单击显示2和最后1然后转到上一个。如何解决这个问题。有人能帮我吗。
这是我的记录活动代码
imageRecord = (ImageView) findViewById(R.id.image_Record);
imageRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickCount += 1;
Log.e("clickCount ", " click !!! " + clickCount);
if (clickCount == 1)
{
btnSaveRecord.setEnabled(false);
btnCancelRecord.setEnabled(false);
myAudioRecorder = new MediaRecorder();
if (vesselId == null) {
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
newAudioFile = 0 + "_" + s.format(new Date()) + ".mp3";
Log.e(" newAudioFile ", " = " + newAudioFile);
outputFile = baseDir + "/classnkk_audio/" + newAudioFile;
Log.e("outputFile ", " = " + outputFile);
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
imageRecord.setImageResource(R.drawable.record);
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
myChronometer.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (vesselId != null) {
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
newAudioFile = vesselId + "_" + s.format(new Date()) + ".mp3";
Log.e(" newAudioFile ", " = " + newAudioFile);
outputFile = baseDir + "/classnkk_audio/" + newAudioFile;
Log.e("outputFile ", " = " + outputFile);
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
imageRecord.setImageResource(R.drawable.record);
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
myChronometer.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (clickCount == 2)
{
btnSaveRecord.setEnabled(true);
btnCancelRecord.setEnabled(true);
imageRecord.setImageResource(R.drawable.record_pause);
myAudioRecorder.stop();
myAudioRecorder.reset();
myAudioRecorder.release();
myAudioRecorder = null;
myChronometer.stop();
long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();
Log.e("elapsedMillis ", " of myChronometer !!! " + elapsedMillis);
}
if (clickCount == 2) {
imageRecord.setImageResource(R.drawable.record);
clickCount = 0;
myAudioRecorder = null;
myChronometer.setBase(SystemClock.elapsedRealtime());
Log.e("(clickCount == 3 ) ", " click !!! " + clickCount);
}
}
});
btnCancelRecord = (Button) findViewById(R.id.buttonCancelRecord);
btnCancelRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ItemDetail_Record.this,
AllPost_ItemDetails.class);
//i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
}
});
btnSaveRecord = (Button) findViewById(R.id.buttonSaveRecord);
btnSaveRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent i = new Intent(ItemDetail_Record.this,
AllPost_ItemDetails.class);
//i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
finish();
startActivity(i);
uploadrecord(strUploadActivityObjectId);
}
});
}
这是我的另一项活动
imgView_BackToAllPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AllPost_ItemDetails.this , CustomActionActivity.class);
finish();
startActivity(i);
}
});
imgButn_AudioRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AllPost_ItemDetails.this, ItemDetail_Record.class);
i.putExtra("DetailView_ActivityId", strActivityId);
startActivityForResult(i, 1234);
}
});