For my app I am making, I have the camera intent run when an activity is created. The problem is that when I click ok for the pic I captured, it just reopens the camera again to take a picture. Here is the code: taken is set to false from another activity. I can confirm that taken is false when this activity starts.
public class QuickEditActivity extends Activity {
public static boolean taken;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quickedit);
if(!QuickEditActivity.taken) {
RunCam();
}
}
private void RunCam() {
QuickEditActivity.taken = true;
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camIntent,1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data != null && data.getExtras() != null) {
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
if(bitmap != null) {
ImageView imgView = (ImageView)findViewById(R.id.CamView);
imgView.setImageBitmap(bitmap);
}
else
{
this.finish();
}
}
else {
this.finish();
}
super.onActivityResult(requestCode, resultCode, data);
}
}