This might be a silly question, but I'm facing problem with safely exiting the `Camera2BasicFragment`. 

I've used the sample code from Google to implement the Camera2 API.
[Google Camera2 Sample code](https://github.com/googlesamples/android-Camera2Basic)

Please suggest where exactly I must put the `Intent` for the next activity where I want to display the captured image and make a safe exit from the camera activity.

The camera just freezes, when I try to navigate to the next activity. I tried closing the camera, stopping the background thread. But I'm not doing it right, due to which the screen freezes. 

I'm trying to achieve it here. Please let me know if I must do it elsewhere. I've used the sample code, if in case you need to refer the code, use the link mentioned above.

Camera2BasicFragment `ImageSaver` function:

```
private class ImageSaver implements Runnable {

        /**
         * The JPEG image
         */
        private final Image mImage;
        /**
         * The file we save the image into.
         */
        private final File mFile;

        ImageSaver(Image image, File file) {
            mImage = image;
            mFile = file;
        }

        @Override
        public void run() {
            ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[buffer.remaining()];
            buffer.get(bytes);
            FileOutputStream output = null;
            try {
                output = new FileOutputStream(mFile);
                output.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                mImage.close();
                if (null != output) {
                    try {
                        output.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            Bitmap capturedImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

            int width = linearLayout.getWidth();
            int height = linearLayout.getHeight();

            int left = width/6;
            int top = height/8;
            Log.e("LEFT TOP", left + " " +top);

            croppedImage = Bitmap.createBitmap(capturedImage, left, top, 5*(width/6), 2*(height/3));

            /**
             * 
             * This is the region of trouble
             * I'm cropping the image and trying to display it in the next activity
             *
             */
            onPause();
            startActivity(new Intent(getActivity(), DisplayImage.class).putExtra("BITMAP", croppedImage));
        }

    }

```

Stack Trace when I try starting the next activity after `ImageSaver()` executes

```
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdb321004 in tid 21857 (CameraBackgroun)
Application terminated.

```