我觉得还是这样做,你还是设置10S刷新,只不过刷新的时候起个子线程去处理数据,然后数据处理完通过handler来通知UI更新(这一过程不考虑10s的限制),10s只是通知数据要去处理了,真正显示可能是在10S以后,然后显示更新成功了,再重启timer计时。
解决方案 »
- android 如何监听 去电(去电,去电,去电) 的接通事件
- 能不能将android4.0的解锁移植到2.3上
- Button ImageView ImageButton有关问题
- android.intent.action.DATE_CHANGED这个广播可靠吗
- 关于拨号界面中optionsmenu的问题(急)
- app打包后无法分享到微信
- 垂直SeekBar setProgress() 成功设置好了值 但是滑块没动
- android的http中的cookie的问题,打印的结果好奇怪哦?求解惑?问倒了很多大神,大家来帮我看一下。
- 新手刚准备安卓开发,搭了环境,新建helloAndroid运行即报错,求教!!
- RecyclerView适配器onBindViewHolder方法执行
- 请问如何播放闹铃的铃声
- Android
用Timer实现的,楼主看看有没有作用?
public void recorder(){
try {
bool = true;
myRecAudioFile = File.createTempFile(strTempFile,".mpg",myRecAudioDir);
recorder = new MediaRecorder();
recorder.setPreviewDisplay(surfaceHolder.getSurface());
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
//设置录音源为麦克风
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//设置输出格式为3gp
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//设置视频大小
recorder.setVideoSize(160,90);
//每秒的帧数
recorder.setVideoFrameRate(5);
//设置视频编码
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
//设置音频编码
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(myRecAudioFile.getAbsolutePath());
recorder.prepare();
recorder.start();
tv01.setVisibility(View.VISIBLE);
tv02.setVisibility(View.VISIBLE);
tv03.setVisibility(View.VISIBLE);
tv04.setVisibility(View.VISIBLE);
tv05.setVisibility(View.VISIBLE);
handler.postDelayed(task, 1000); recording = true;
isStopRecord = false;
} catch (IOException e) {
e.printStackTrace();
}
}
//停止录像
public void stop(){
if (recorder == null){
return;
}
recorder.stop(); bool = false; tv01.setText(format(hour));
tv03.setText(format(minute));
tv05.setText(format(second));
recorder.release();
recording = false;
recorder = null;
mMakeTextToast("停止:" + myRecAudioFile.getName(),true);
// 停止录象
isStopRecord = true;
}
//定时器设置,实现计时
private Handler handler = new Handler();
private Runnable task = new Runnable() {
public void run() {
if(bool){
handler.postDelayed(this, 1000);
second ++;
if(second < 60){
tv05.setText(format(second));
}else if(second < 3600){
minute = second / 60;
second = second % 60;
tv03.setText(format(minute));
tv05.setText(format(second));
}else{
hour = second / 3600;
minute = (second % 3600) / 60;
second = (second % 3600) % 60;
tv01.setText(format(hour));
tv03.setText(format(minute));
tv05.setText(format(second));
}
}
}
};