2

I have an activity that will take a picture upon touch of the screen. After taking the picture, I'd like to switch to a different activity. The structure of the code looks like the following:

class MyActivity extends Activity implements onTouchListener {
    ...
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        mCameraView.takePicture();
        // Intent intent = new Intent(whatever);
        // startActivity(intent);
        return false;
    }
   }

As shown, if I commented out the startActivity, then picture is taken and saved correctly. If I attempt to start the activity AFTER taking the picture, then the picture is not saved correctly (size 0). I don't know for sure if the picture taking is in a separate thread or not, but even if it is, it should eventually saved, but that doesn't appear to be the case. Any idea how to resolve this?

Aleks G
  • 56,435
  • 29
  • 168
  • 265
Oliver
  • 3,592
  • 8
  • 34
  • 37

1 Answers1

0

Start your activity at the end of Camera.PictureCallback()

mCameraView.takePicture(new Camera.ShutterCallback() {

                    @Override
                    public void onShutter() {
                        Log.e("Shutter closed", "   SHUTTER    callback");

                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] arg0, Camera arg1) {
                        Log.e("Picture taken",
                                "   RAW    image    callback");
                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] arg0, Camera arg1) {
                        Log.e("Picture taken",
                                "   POSTVIEW    image    callback");
                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] data, Camera camera) {
                        // Start Activity here after saving image
                    }
                });


            }
        }
    };
AnujMathur_07
  • 2,586
  • 2
  • 18
  • 25
  • This method works on taking the first picture. Upon taking the second shot, OOM (Out of Memory) kicks in. It may not related to the method per se though, still looking into it. Thanks – Oliver May 21 '13 at 14:05
  • OOM occur due to less memory for your application. May be the `Bitmap` you are creating is large. – AnujMathur_07 May 21 '13 at 14:07
  • This might help http://stackoverflow.com/questions/8419140/java-lang-outofmemoryerror-in-android-while-saving-picture-taken-from-camera – AnujMathur_07 May 21 '13 at 14:10