Note that there are some explanatory texts on larger screens.

plurals
  1. POReopening camera after intent chooser is canceled
    primarykey
    data
    text
    <p>I have created a custom camera preview view <code>CameraView</code> which extends <code>SurfaceView</code>, and it also implements <code>SurfaceHolder.Callback</code> interface. The view operates with the camera. When you open the view it shows a camera preview. On the same screen there is also overlay with two buttons - 'Take picture', 'Choose from gallery'. The activity that holds the <code>CameraView</code> releases and reopens the camera in <code>onPause()</code> and <code>onResume()</code> methods.</p> <p>If I click the 'Choose from gallery' button, the following intent is created:</p> <pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, LOAD_PICTURE); </code></pre> <p>If there is only one activity that can respond to this intent then it's fine. The activity gets automatically opened, the camera is released. I can also hit back when on the gallery and I will get back into the <code>CameraView</code> activity, and camera preview is restored.</p> <p>The interesting part starts if there are multiple activities that can handle this intent, and the intent chooser dialog pops up. When intent chooser dialog spawns, <code>onPause()</code> gets called in parent activity and camera gets released, the screen becomes black. If I dont choose intent from the dialog, but instead click back button on the phone <code>onResume()</code> is called, but camera preview is never coming back. To get the camera preview to show again, I need to go back to previous activity and go back inside the preview activity.</p> <p>The following problem happens because, when the dialog is raised only <code>onPause()</code> gets called, but if I actually switch to different activity <code>surfaceDestroyed()</code> get called also. The same is true for <code>onResume()</code> when the dialog is canceled with back button, <code>surfaceChanged()</code> and <code>surfaceCreated()</code> never gets called.</p> <p>My question is how to get camera preview to reappear if the intent chooser dialog is canceled. Is there a way how to trigger <code>SurfaceHolder.Callback</code> methods explicitly? I know that there are hidden <code>hideSurface()</code> and <code>showSurface()</code> in <code>SurfaceView</code>, but I don't want to go this route.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload