BackPress After Taking Photo with Camera is Unreliable - OnActivityResult Not Reached RRS feed

  • Question

  • User118366 posted

    Really stumped here. My activity is designed to capture & display images in an imageView. When started, it will cycle thru images already captured (if any), one at a time, and has a button to launch the camera to capture more.

    To launch the camera app I am using the commonly accepted method.... Intent intent = new Intent (MediaStore.ActionImageCapture); file = new Java.IO.File (dir, filename); intent.PutExtra (MediaStore.ExtraOutput, Android.Net.Uri.FromFile (file)); StartActivityForResult (intent, intent_camera);

    And the return point is as follows.......... protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data) { base.OnActivityResult (requestCode, resultCode, data); Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile); Android.Net.Uri uri = Android.Net.Uri.FromFile (file); mediaScanIntent.SetData (uri); SendBroadcast (mediaScanIntent);

            bitmap = file.Path.LoadAndResizeBitmap (width, height, true);
            imgWorkflow.SetImageBitmap (bitmap);

    The flow of the activity is as follows: 1 - user clicks button to launch camera (as above) 2 - when camera closes, the image is returned and displayed on screen in an imageView 3 - if the user clicks the button again, the imageView is cleared and continue at (1)

    This activity works fine when capturing and displaying the first image

    But if the user wants more photos (3) the camera is re-launched using the same process but after a picture is captured and saved, the backpress seems to relaunch the camera instead of returning to my code at OnActivityResult. If the user tries again to hit backpress a few more times, the code sometimes returns back into my code, and if I add a breakpoint in the OnActivityResult code, the breakpoint is hit several times, almost as if all the backpresses are all being processed together.

    I can't be sure if the number of backpresses required is in some way related to the the number of images captured but it does seem to take more backpresses each time another image is captured. Eventually it stops returning.

    I have seen that a number of people have experienced problems with this but have never seen a definitive solution. I know that my activity may have been paused but I find it hard to accept that android would happily close down or put to sleep an app which has created an intent for another app and is waiting patiently for a return.

    That said, I am certainly not an android expert and am hoping that someone here has seen all this before and knows exactly what I am forgetting or doing wrong !

    Monday, July 27, 2015 12:40 AM

All replies

  • User118366 posted

    This has now been resolved

    Monday, July 27, 2015 2:42 PM