RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 407 forks source link

CameraView content is not shown on resuming after several minutes #286

Open ValeriiVolkov opened 6 years ago

ValeriiVolkov commented 6 years ago

Steps to reproduce:

  1. Hide app. (fotoapparat.stop() is called)
  2. Resume app after several minutes (fotoapparat.start() is called) Actual result: Camera content is not shown

The following messages in logs:

08-21 17:16:26.854 897-1659/? E/Camera2ClientBase: setPreviewTarget: attempt to use a locked camera from a different process (old pid 0, new pid 4511) 08-21 17:16:26.864 897-1659/? E/Camera2ClientBase: stopPreview: attempt to use a locked camera from a different process (old pid 0, new pid 4511)

Initialized fotoapparat in the following way:

Fotoapparat
    .with(this)
    .frameProcessor(frameProcessor)
    .into(cameraView)
    .previewScaleType(ScaleType.CenterCrop)
    .photoResolution(highestResolution())
    .lensPosition(front())
    .build()

Context:

sraka1 commented 5 years ago

@ValeriiVolkov how did you resolve this issue?

ernkoch commented 5 years ago

I facing the issue on Pixel 2 (Android API 27, 28)

ValeriiVolkov commented 5 years ago

@sraka1 Telling the truth I don't remember what was the fix. There were some major changes in the code base. Overall I recommend to try the following:

  1. Switch calling fotoapparat.start() between onResume and onStart.
  2. Add delay for calling fotoapparat.start(). In my case after refactoring, it called with some delay after an observer was notified that camera permission is granted.

I will reopen the issue - maybe others also faced the same issue and know the exact reason.