[英]Xamarin.Forms: Error Navigation after picking photo from gallery
我正在使用Xam.Plugin.Media從圖庫或相機中挑選照片。 在iOS中,它工作得很好但在Android中測試,在從庫中挑選照片后,當嘗試無法導航到另一個頁面時,應用程序崩潰。
錯誤:Java.Lang.IlegalStateExecution:在onSaveInstanceState之后無法執行此操作
這是我的代碼:
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());
}
提前致謝。
我猜這可能是一個線程問題,因為從您的圖像選擇意圖返回時,您的代碼看起來可能無法在主UI線程中運行。
嘗試通過你的導航電話
Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
await Navigation.PushAsync(new testePage())
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.