添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
瘦瘦的山羊  ·  Nginx “If Is ...·  1 年前    · 
飞翔的遥控器  ·  WPF 关于 ComboBox ...·  1 年前    · 
重感情的黄花菜  ·  istio kiali ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I know how to return to previous activity as usual.The current activity( VideoActivity.java ) is having the SurfaceView for the MediaRecorder to record video. Whenever I implement the finish() to return to previous activity, it causing the error like logcat below:

E/BufferQueueProducer: [SurfaceView] dequeueBuffer: BufferQueue has been abandoned 
E/EmulatedCamera_Preview: onNextFrameAvailable: Unable to dequeue preview window buffer: 19 -> No such device

The logcat just repeat the above 2 line and become very long list,therefore I just show this 2 line.

Besides showing the logcat above,whenever I intent to VideoActivity.java the application is stop.

This is how I implement to return to the previous activity

backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isRecording){
                    stopRecording();
                    finish();
                }else{
                    finish();

Basically I implement the SurfaceView like this:

public class VideoActivity extends AppCompatActivity implements SurfaceHolder.Callback{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);
    surfaceHolder = videoSurface.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(isRecording){
                stopRecording();
                finish();
            }else{
                finish();
@Override
public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
    }catch (RuntimeException ex){
        ex.printStackTrace();
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();
    }catch (Exception e){
        e.printStackTrace();
    prepareRecorder();
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    mRecorder.reset();
    mRecorder.release();
    mCamera.release();
    // once the objects have been released they can't be reused
    mRecorder = null;
    mCamera = null;    }

This code is working fine before I return to previous activity using finish().

So my question is,if an activity having SurfaceView,how can it return to previous activity?Please show me the right way.

I realize I didnt release the Camera and MediaRecorder.I able to solve this by release the Camera and mediaRecorder before finish(),so the code is look like this

back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isRecording){
                    Log.d("Video","stop recording");
                   mRecorder.stop();
            }catch (RuntimeException e) {
            releaseMediaRecorder();
            mCamera.lock();
            isRecording = false;
            releaseCamera();
                    finish();
                }else{
                    releaseCamera();
                    finish();
private void releaseCamera(){
        if (mCamera != null){
            // release the camera for other applications
            mCamera.setPreviewCallback(null);
            surfaceHolder.removeCallback(VideoActivity.this);
            mCamera.release();
            mCamera = null;
private void releaseMediaRecorder(){
        if (mRecorder != null) {
            // clear recorder configuration
            mRecorder.reset();
            mRecorder.release();
            mRecorder = null;
            mCamera.lock();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.