in my app when a button is clicked it opens the camera to capture the image. the camera code is as follows…
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(), String.valueOf(System.currentTimeMillis()) + ".jpg");
Log.e("ffffffffffiiiiiiiiilllllllllle ",""+file);
f = String.valueOf(file);
mCapturedImageURI = Uri.fromFile(file);
Log.e("outputFileUri ",""+mCapturedImageURI);
setupImage(intent);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, 3);
on start activity result i am showing an alert box with two buttons. If the button1 is clicked the image will be upload to an url and if button 2 is clicked it will be uploaded to another url.
Now the problem is if the camera gets opened and the image is not captured, to go back to the previous activity the user use to click the back button and by this time also the alert box use to appear. Either the user clicks the button1 or button2 the app gets crashed.
How to avoid the alert box when the back button is pressed without capturing the image.
inside your
onActivityResult()first check if the result is O.K. if its O.K then you can proceed to next steps. else nothing will be processed.