There are lines in the code

camera.takePicture(null, null, new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) {.....делаем фото.....} 

Next comes the code that is not associated with the camera. Various actions. And at the end of the code I open another layout.

The problem is that the code that is not associated with the camera is processed, the layout is opened .. And only then the Callback processed
Since the new layout overlaps the surfaceView snapshot cannot be done. And I need it =)

Code snippet:

 try { GetPic(); } catch (IOError e) {} Thread.currentThread(); Thread.sleep(500); Intent intent = new Intent() .setClass(MainActivity.this, mail.class); startActivityForResult(intent, 1); TextForFile = TextForFile + "Photo_" + date2+ ".jpg"+";"; //запись текстового файла try { OutputStream ToRecordsFile; ToRecordsFile=new FileOutputStream(photoFile + File.separator+"r.csv",true); OutputStreamWriter sw=new OutputStreamWriter(ToRecordsFile); sw.write(TextForFile); sw.close();//Закрыли } catch (IOException e) { Log.e("MyError", "Не создался writer", e); } //запись текстового файла //////////////////////////////////////////////////// 

GetPic () function:

 private void GetPic() { try { camera.takePicture(null, null, new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) {try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); fos.close(); } catch (Exception e) { e.printStackTrace(); }} }); } catch(Exception e) {} 
  • @selgkos you yourself understand your question? - Barmaley

1 answer 1

code that is not associated with the camera. Various actions. And at the end of the code I open another Lyaut.

So do these "various actions" after calling onPictureTaken . And launch a new Activity in the same way after working off the camera callback.

  • In the code they are executed after. If you look at the debugger, the flask is processed at the end of the procedure. So far, a slight pause after onPictureTaken has helped. Surprisingly. - selgkos
  • As I understand from your question, the code that performs the "various actions" is immediately after camera.takePicture(…) . In general, show the code. It seems to me that you are doing something wrong, since it came to crutches in the form of a "pause after onPictureTaken". - falstaf