Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: camera's startPreview method not working after stopPreview
    primarykey
    data
    text
    <p>In my application i have an image button that basically switches on and off the flash LED. The code is running fine for the first time i.e. On first Click it Switches On the LED and on the Second Click it Switches it Off. But then Nothing happens third Click onwards. I am testing this on Nexus S.</p> <p>Following is the Code for the ImageButton Click Method.</p> <pre><code>public void ToggleTorch(){ final ImageButton tt = (ImageButton)findViewById(R.id.tt); tt.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ if (isFlashOn){ mycam.stopPreview(); isFlashOn = false; } else { mycam.startPreview(); isFlashOn = true; } } }); } </code></pre> <p>From what i think, it has to do something with the SurfaceView as i think it is not being destroyed while calling stopPreview but i am not sure.. </p> <p>Following is the Code for the onCreate Method.</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Check if Flash Light is Available Boolean has_flash = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); if(has_flash){ setContentView(R.layout.activity_main); SurfaceView preview = (SurfaceView)findViewById(R.id.pSv); SurfaceHolder holder = preview.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); disableSleepMode(); initFlashLight(); ToggleTorch(); screenTorchOn(); } else { setContentView(R.layout.activity_main); disableSleepMode(); screenTorchOn(); } } </code></pre> <p>any help would be appreciated. Thanks.</p>
    singulars
    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