Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult getting called as soon as camera intent is sent

I am using the camera intent to launch the camera in my app but as soon as the intent gets fired the onActivityResult gets fired and I have not even taken a picture yet.

When I do take a picture, select it and return back to my activity the onActivityResult does not get called at all

here is how I launch the camera

PackageManager pm = getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        File tempDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Mobile Map");
        if (!tempDir.exists()) {
            if (!tempDir.mkdir()) {
                Toast.makeText(this,
                        "Please check SD card! Image shot is impossible!",
                        Toast.LENGTH_SHORT).show();
            }
        }

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US).format(new Date());
        File mediaFile = new File(tempDir.getPath() + File.separator+ "IMG_" + timeStamp + ".jpg");

        photoUri = Uri.fromFile(mediaFile);
        camera.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
        startActivityForResult(camera, CAMERA_REQUEST);
    } else {
        Toast.makeText(this,"This device does not have a rear facing camera",Toast.LENGTH_SHORT).show();
    }

Why is the onActivityResult only getting called after the camera intent launches?

like image 250
tyczj Avatar asked May 16 '13 16:05

tyczj


1 Answers

The problem was that in my manifest I had the activity set to singleInstance and apparently startActivityForResultdoes not like that

like image 142
tyczj Avatar answered Sep 28 '22 09:09

tyczj