androidxamarinimage-gallerystartactivityforresult

Android TransactionTooLargeException selecting image gallery


I've built an Android application with Xamarin that contains a function that allows users to select an Image. In some devices it works but in other devices it trows following exception:

java.lang.RuntimeException: android.os.TransactionTooLargeException

Here's my code.

var intent = new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri);

intent.SetType("image/*");
StartActivityForResult(Intent.CreateChooser(intent, Resources.GetString(Resource.String.selectImage)), SELECT_FILE);

It shows the chooser and, when I choose "Image Gallery" the exception throws.

Searching on google I found some posts where people suggested to check the dimension of the image passed between two activities but in that case it crashes before the selection of the image.

Can anyone help me?

Thanks in advance


Solution

  • Searching on google I found some posts that suggested to manage OnSaveInstanceState event, on the activity, to save bundle. This event is called when user chooses "Image Gallery".

    Following is the event code:

    protected override void OnSaveInstanceState(Bundle outState)
        {
            base.OnSaveInstanceState(outState);
    
            if (outState != null)
                outState.Clear();
        }