Android activity killed when taking pictures using MediaPlugin

I am trying to take a picture and send it to a server using MediaPlugin. However android kills my application when switches to the camera, is there any way i can prevent this.

this is my method:

async void OnCameraClicked(object sender, EventArgs e)
        {
            await Plugin.Media.CrossMedia.Current.Initialize();

            var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
            {
                //SaveToAlbum = true, 
                CompressionQuality = 92,
                PhotoSize = PhotoSize.Medium,
            });

            if (photo != null)
            {
                var expenseReg = (Expenses)BindingContext;
                using (var memoryStream = new MemoryStream())
                {
                    photo.GetStream().CopyTo(memoryStream);
                    expenseReg.Photo = memoryStream.ToArray();

                    //optional, display the photo
                    Photo.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
                    photo.Dispose();
                }
                Photo.IsVisible = true;
            }
        }

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    Have you followed all the instructions here on setting it up?
    https://github.com/jamesmontemagno/MediaPlugin

    If you do everything correctly, It will work.

  • pKorsholmpKorsholm Member

    The issue is that my application is not resumed after the camera closes it just returns to the android home screen.

  • acceleratoraccelerator NOMember ✭✭
    edited August 2018

    Check if you have enabled "Do not keep activities". MainActivity will get destroyed. Xamarin.Forms only uses one activity.

Sign In or Register to comment.