简体   繁体   English

Xamarin.Forms:从图库中选择照片后导航错误

[英]Xamarin.Forms: Error Navigation after picking photo from gallery

I'm using Xam.Plugin.Media to pick a photo from gallery or camera. 我正在使用Xam.Plugin.Media从图库或相机中挑选照片。 In iOS it works all fine but testing in android, after picking the photo from the gallery the app crashs when tries no navigate to another page. 在iOS中,它工作得很好但在Android中测试,在从库中挑选照片后,当尝试无法导航到另一个页面时,应用程序崩溃。

Error: Java.Lang.IlegalStateExecution: Can not perform this action after onSaveInstanceState 错误:Java.Lang.IlegalStateExecution:在onSaveInstanceState之后无法执行此操作

Here's my code: 这是我的代码:

private async void SelectPicture(PostModel p)
    {


        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await DisplayAlert("Photos Not Supported", "Permission not granted to photos.", "OK");
            return;
        }
        var file = await CrossMedia.Current.PickPhotoAsync();


        if (file == null)
            return;



        selfieImg.Source = ImageSource.FromStream(() =>
        {
            var stream = file.GetStream();
            file.Dispose();
            return stream;
        });


        await Navigation.PushAsync(new testePage());

    }

Thanks in advance. 提前致谢。

I would guess that this might be a threading issue, since your code looks like it might not run in the main UI thread when returning from your Image selection intent. 我猜这可能是一个线程问题,因为从您的图像选择意图返回时,您的代码看起来可能无法在主UI线程中运行。

try doing your navigation call via 尝试通过你的导航电话

Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
    await Navigation.PushAsync(new testePage())
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM