我有一个带有按钮的活动。在 ACTION_DOWN 上,我开始录制并在按下此按钮的同时继续录制。在 ACTION_UP 我必须停止录制。录音线程是单独的一个。活动上有一个文本视图,显示记录时间。时间的默认值为“00:00:00:000”来自记录线程即时调用活动类的 updateTime 方法:
public void updateTime(final String time) {
Log.d("***UPDATE TIME Thread", "Current time:" + time);
runOnUiThread(new Runnable() {
public void run() {
timerTextView.setText(time);
Log.d("UPDATE TIME Thread", "Current time:"+time);
}
});
}
当我第一次调用此活动时,它可以正常工作并正确更新时间值。但是,如果我从上一个屏幕中选择相同的选项来开始第二次录制,时间文本视图的值将保持与“00:00:00:000”相同,其中第二个 Log.d 代码行显示了正确的值。这是 LogCat
02-25 16:07:10.660: D/Recording(5075): Start
02-25 16:07:10.695: D/***UPDATE TIME Thread(5075): Current time:00:00:00:032
02-25 16:07:10.711: D/UPDATE TIME Thread(5075): Current time:00:00:00:032
02-25 16:07:10.843: D/***UPDATE TIME Thread(5075): Current time:00:00:00:174
02-25 16:07:10.863: D/UPDATE TIME Thread(5075): Current time:00:00:00:174
02-25 16:07:10.945: D/***UPDATE TIME Thread(5075): Current time:00:00:00:280
02-25 16:07:10.972: D/UPDATE TIME Thread(5075): Current time:00:00:00:280
02-25 16:07:11.082: D/***UPDATE TIME Thread(5075): Current time:00:00:00:418
02-25 16:07:11.089: D/UPDATE TIME Thread(5075): Current time:00:00:00:418
02-25 16:07:11.203: D/***UPDATE TIME Thread(5075): Current time:00:00:00:535
02-25 16:07:11.222: D/UPDATE TIME Thread(5075): Current time:00:00:00:535
02-25 16:07:11.351: D/***UPDATE TIME Thread(5075): Current time:00:00:00:676
......
Here is my Activity Class Code
公共类 VerficationPBActivity 扩展 Activity 实现 VoiceManagerListener, OnTouchListener { private Claimant currentClaimant = null; TextView screenHeading = null; 私有字符串 screenHeadingText = null; TextView textToSpeakTextView = null; TextView timerTextView = null; TextView statusHintTextView = null; 私人按钮 pushToRecordButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verfication_pb);
ActivityController.getActivityController().setCurrentActivity(this);
screenHeading = (TextView) findViewById(R.id.screenHeading);
textToSpeakTextView = (TextView) findViewById(R.id.text_to_speek);
timerTextView = (TextView) findViewById(R.id.timer);
statusHintTextView = (TextView) findViewById(R.id.status_hint);
screenHeadingText = (String) getIntent().getSerializableExtra("heading");
currentClaimant = (Claimant) getIntent().getSerializableExtra("claimant");
screenHeading.setText(screenHeadingText);
if (currentClaimant != null) {
textToSpeakTextView.setText(currentClaimant.getNextPrompt());
statusHintTextView.setText(currentClaimant.getStatusHint());
}
pushToRecordButton = (Button) findViewById(R.id.pushToRecord);
pushToRecordButton.setOnTouchListener(this);
}
@Override
public void updateTime(final String time) {
Log.d("***UPDATE TIME Thread", "Current time:" + time);
runOnUiThread(new Runnable() {
public void run() {
timerTextView.setText(time);
Log.d("UPDATE TIME Thread", "Current time:"+time);
Log.d("UPDATE TIME Thread", "Current value:"+timerTextView.getText());
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
VoiceManager.getInstance().startRecording();
break;
case MotionEvent.ACTION_UP:
Log.d("Push Button Down", "Up Event Fired");
VoiceManager.getInstance().stop();
String audioDataBase64 = VoiceManager.getInstance().getAudioDateinBase64Encoding();
if (screenHeadingText.equals("Verification")) {
VBSServiceManager.getInstance().processVerification(currentClaimant, audioDataBase64);
} else {
VBSServiceManager.getInstance().processEnrollment(currentClaimant, audioDataBase64);
}
break;
}
return false;
}
}