Pause activity while waiting for PictureCallback to appear

I am creating an Android application where I would like to wait until PictureCallback appears before the call continues.

import android.hardware.Camera;

private Camera camera
private Bitmap picture;

camera.takePicture(null, null, new PictureCallback() {
  @Override
  public void onPictureTaken(byte[] data, Camera camera) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;
    picture = BitmapFactory.decodeByteArray(data , 0, data.length, options);
  }
}

... do some other logic with picture

I would like other logic to be shared, and so I would like to avoid encoding this in the takePicture function.

Can this be done?

+5
source share
2 answers

It’s bad practice to block the user interface flow when doing any background work.

If you invoke the built-in Camera activity, your activity will be in the background. After you take a picture and the camera activity is closed, the image will be saved by the time you return to your work.

Camera, ProgressDialog, - , .

0

. , PictureCallback wait() . , PictureCallback , notify(), , . . , /, .

0

All Articles