使用 Xamarin Essential 选择联系人(并尝试返回)时应用程序崩溃
App Crashing when selecting Contact (and trying to go back) using Xamarin Essential
我尝试使用 Xamarin Essential API 来选择和显示单个联系人。不幸的是,一旦我 select 来自我的模拟器的联系人,该应用程序就会进入后台。尝试从应用仪表板 select 应用时,它 returns 返回到它的第一页。
此外,在联系人 window 中,如果我按下后退按钮(硬件后退按钮或导航栏中的后退按钮),应用程序会崩溃。
所以在这两种方式中,我都无法访问正在显示的联系人。
令人惊讶的是,当我设置断点时,我可以看到 selected 联系人进来了。我可以看到所有数据。
我正在使用 MvvmCross,我的参考点是 James Montemagno 的最新 Xamarin.Essential 联系人 API 视频和联系人 API Xamarin.Forms 文档。
这是我的文件:
MainActivity.cs
//[Activity(Label = "Vary.Core", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
[Activity(Label = "Vary.Core", MainLauncher = true, Theme = "@style/MainTheme", NoHistory = true)]
public class MainActivity : MvxFormsAppCompatActivity<Setup, Core.MvxApp, App> //MvxFormsAndroidSetup<Core.MvxApp, App> //Setup
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
//LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnResume()
{
base.OnResume();
Xamarin.Essentials.Platform.OnResume();
}
protected override void OnPause()
{
base.OnPause();
}
ContactDisplayViewModel.cs
namespace Vary.Core.ViewModels
{
public class ContactDisplayViewModel : MvxViewModel
{
#region Private variables
private readonly IMvxNavigationService navigationService;
#endregion
#region Properties
private bool isSingleContactRequired;
public bool IsSingleContactRequired
{
get => isSingleContactRequired;
set
{
isSingleContactRequired = value;
RaisePropertyChanged(() => IsSingleContactRequired);
}
}
private string contactInformation;
public string ContactInformation
{
get => contactInformation;
set
{
contactInformation = value;
RaisePropertyChanged(() => ContactInformation);
}
}
#endregion
#region Commands
public IMvxCommand SelectSingleContactCommand => new MvxCommand(OnSelectSingleContactSelected);
public MvxCommand DisplayAllContactsCommand => new MvxCommand(OnDisplayAllContactsSelected);
#endregion
#region Command Events
async void OnSelectSingleContactSelected()
{
try
{
var contact = await Contacts.PickContactAsync();
if (contact == null)
return;
var contactInfo = new StringBuilder();
contactInfo.AppendLine(contact.DisplayName);
contactInfo.AppendLine(contact.FamilyName);
contactInfo.AppendLine(contact.Emails.FirstOrDefault().ToString());
contactInfo.AppendLine(contact.Phones.FirstOrDefault().ToString());
IsSingleContactRequired = true;
ContactInformation = contactInfo.ToString();
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
void OnDisplayAllContactsSelected()
{
}
#endregion
#region .Ctor
public ContactDisplayViewModel(IMvxNavigationService navigationService)
{
this.navigationService = navigationService;
}
#endregion
#region Override Methods
public override void Prepare()
{
base.Prepare();
IsSingleContactRequired = false;
}
#endregion
}
}
ContactDisplayView.xaml
<Button Grid.Row="0"
Grid.Column="0"
BackgroundColor="Transparent"
Text="Pick A Contact"
Command="{Binding SelectSingleContactCommand}"/>
<Label Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Text="{Binding ContactInformation}"
TextColor="DarkOrange"
IsVisible="{Binding IsSingleContactRequired}"/>
有没有人在尝试从任何此类 native/system 定义的应用程序导航回您的 Xamarin.Forms 应用程序时遇到此崩溃,或者一般来说,任何崩溃问题?
这是应用程序输出:
[Mono] Assembly Loader probing location: '/Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/sdks/out/android-x86-release/lib/Xamarin.Forms.Platform.Android.AppLinks.exe'.
[Mono] Assembly Loader probing location: '//Facades/Xamarin.Forms.Platform.Android.AppLinks.exe'.
[Mono] Requesting loading reference 13 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 13 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Legacy.Support.Core.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.Legacy.Support.Core.UI[0xe6461de0]: 2
[Mono] Requesting loading reference 3 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll asmctx DEFAULT, looking for Xamarin.AndroidX.DrawerLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Requesting loading reference 2 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
[Mono] Assembly Ref addref Xamarin.AndroidX.Legacy.Support.Core.UI[0xe6461de0] -> Java.Interop[0xe649f180]: 21
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_static_int_method_a'.
[Mono] Probing 'java_interop_jnienv_call_static_int_method_a'.
[Mono] Found as 'java_interop_jnienv_call_static_int_method_a'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_int_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_int_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_int_method_a'.
Thread started: #12
[HostConnection] HostConnection::get() New Host Connection established 0xc0ada410, tid 17005
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
[OpenGLRenderer] Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
[eglCodecCommon] setVertexArrayObject: set vao to 0 (0) 0 0
[EGL_emulation] eglCreateContext: 0xe650a220: maj 3 min 0 rcv 3
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[Gralloc3] mapper 3.x is not supported
[HostConnection] createUnique: call
[HostConnection] HostConnection::get() New Host Connection established 0xbe2518a0, tid 17005
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
[eglCodecCommon] allocate: Ask for block of size 0x1000
[eglCodecCommon] allocate: ioctl allocate returned offset 0x3ff24c000 size 0x2000
[Mono] Requesting loading reference 8 (of 9) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Vary.Core.Android.dll
[Mono] Loading reference 8 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Vary.Core.Android.dll asmctx DEFAULT, looking for Xamarin.Forms.Platform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Vary.Core.Android[0xe64538c0] -> Xamarin.Forms.Platform[0xe64639a0]: 3
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[eglCodecCommon] setVertexArrayObject: set vao to 0 (0) 1 0
[Mono] Requesting loading reference 11 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 11 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.Core[0xe6461900]: 7
[Mono] Requesting loading reference 16 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 16 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.SwipeRefreshLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040]: 2
[Mono] Requesting loading reference 3 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040] -> Xamarin.AndroidX.Core[0xe6461900]: 8
[Mono] Requesting loading reference 2 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
[Mono] Assembly Ref addref Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040] -> Java.Interop[0xe649f180]: 22
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_static_void_method_a'.
[Mono] Probing 'java_interop_jnienv_call_static_void_method_a'.
[Mono] Found as 'java_interop_jnienv_call_static_void_method_a'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_float_method_a'.
[Mono] Probing 'java_interop_jnienv_call_float_method_a'.
[Mono] Found as 'java_interop_jnienv_call_float_method_a'.
2021-03-05 03:03:56 [TRACE] (MvxForms) PresentationAttribute not found for ContactDisplayViewModel. Assuming ContentPage presentation
2021-03-05 03:03:56 [TRACE] (MvvmCross.Logging.MvxLog) No view model association found for candidate view MainActivity
2021-03-05 03:03:56 [TRACE] (MvvmCross.Logging.MvxLog) No view model association found for candidate view MainActivity
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_is_assignable_from'.
[Mono] Probing 'java_interop_jnienv_is_assignable_from'.
[Mono] Found as 'java_interop_jnienv_is_assignable_from'.
Resolved pending breakpoint at 'ContactDisplayViewModel.cs:67,1' to void Vary.Core.ViewModels.ContactDisplayViewModel.<OnSelectSingleContactSelected>d__13.MoveNext () [0x0015b].
[Mono] Requesting loading reference 5 (of 8) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Essentials.dll
[Mono] Loading reference 5 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Essentials.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Essentials[0xe64636a0] -> System.Core[0xe64a0140]: 9
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_object_field'.
[Mono] Probing 'java_interop_jnienv_get_object_field'.
[Mono] Found as 'java_interop_jnienv_get_object_field'.
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[Mono] Requesting loading reference 12 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 12 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> System.Runtime.Serialization[0xe64a17c0]: 4
[Mono] DllImport searching in: 'libmono-native.so' ('./libmono-native.so').
[Mono] Searching for 'SystemNative_MkDir'.
[Mono] Probing 'SystemNative_MkDir'.
[Mono] Found as 'SystemNative_MkDir'.
[Mono] Requesting loading reference 21 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 21 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> System.Xml[0xe64a16a0]: 7
[System] A resource failed to call close.
[System] A resource failed to call close.
全部代码:
public partial class MainPage : ContentPage, INotifyPropertyChanged
{
public Command SelectSingleContactCommand
{
get
{
return new Command(val =>
{
OnSelectSingleContactSelected();
});
}
}
private bool _isSingleContactRequired;
public bool IsSingleContactRequired
{
get
{
return _isSingleContactRequired;
}
set
{
if (_isSingleContactRequired != value)
{
_isSingleContactRequired = value;
NotifyPropertyChanged("IsSingleContactRequired");
}
}
}
private string _contactInformation;
public string ContactInformation
{
get
{
return _contactInformation;
}
set
{
if (_contactInformation != value)
{
_contactInformation = value;
NotifyPropertyChanged("ContactInformation");
}
}
}
public MainPage()
{
InitializeComponent();
this.BindingContext = this;
}
async void OnSelectSingleContactSelected()
{
try
{
var contact = await Contacts.PickContactAsync();
if (contact == null)
return;
var contactInfo = new StringBuilder();
contactInfo.AppendLine(contact.DisplayName);
contactInfo.AppendLine(contact.FamilyName);
contactInfo.AppendLine(contact.Emails.FirstOrDefault().ToString());
contactInfo.AppendLine(contact.Phones.FirstOrDefault().ToString());
IsSingleContactRequired = true;
ContactInformation = contactInfo.ToString();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
截图:
好吧,经过几个月的零星和频繁检查,经过大量的代码更改和大修,在 MainActivity 文件中发现了问题。
应从 MainActivity.cs 中删除“NoHistory = true”,否则一旦应用程序进入后台,它会删除您 activity 的所有历史记录,您将无法返回!因此应用程序崩溃(或者你可以说它进入后台,当你尝试从最近打开它时,你会得到第一个 activity/scree/view 模型)!
这么简单的解决这个缺陷,我哭笑不得!
P.S : 这解决了图像选取、文件选取和联系人选取的所有崩溃问题!
干杯!
我尝试使用 Xamarin Essential API 来选择和显示单个联系人。不幸的是,一旦我 select 来自我的模拟器的联系人,该应用程序就会进入后台。尝试从应用仪表板 select 应用时,它 returns 返回到它的第一页。
此外,在联系人 window 中,如果我按下后退按钮(硬件后退按钮或导航栏中的后退按钮),应用程序会崩溃。 所以在这两种方式中,我都无法访问正在显示的联系人。
令人惊讶的是,当我设置断点时,我可以看到 selected 联系人进来了。我可以看到所有数据。
我正在使用 MvvmCross,我的参考点是 James Montemagno 的最新 Xamarin.Essential 联系人 API 视频和联系人 API Xamarin.Forms 文档。
这是我的文件:
MainActivity.cs
//[Activity(Label = "Vary.Core", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
[Activity(Label = "Vary.Core", MainLauncher = true, Theme = "@style/MainTheme", NoHistory = true)]
public class MainActivity : MvxFormsAppCompatActivity<Setup, Core.MvxApp, App> //MvxFormsAndroidSetup<Core.MvxApp, App> //Setup
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
//LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnResume()
{
base.OnResume();
Xamarin.Essentials.Platform.OnResume();
}
protected override void OnPause()
{
base.OnPause();
}
ContactDisplayViewModel.cs
namespace Vary.Core.ViewModels
{
public class ContactDisplayViewModel : MvxViewModel
{
#region Private variables
private readonly IMvxNavigationService navigationService;
#endregion
#region Properties
private bool isSingleContactRequired;
public bool IsSingleContactRequired
{
get => isSingleContactRequired;
set
{
isSingleContactRequired = value;
RaisePropertyChanged(() => IsSingleContactRequired);
}
}
private string contactInformation;
public string ContactInformation
{
get => contactInformation;
set
{
contactInformation = value;
RaisePropertyChanged(() => ContactInformation);
}
}
#endregion
#region Commands
public IMvxCommand SelectSingleContactCommand => new MvxCommand(OnSelectSingleContactSelected);
public MvxCommand DisplayAllContactsCommand => new MvxCommand(OnDisplayAllContactsSelected);
#endregion
#region Command Events
async void OnSelectSingleContactSelected()
{
try
{
var contact = await Contacts.PickContactAsync();
if (contact == null)
return;
var contactInfo = new StringBuilder();
contactInfo.AppendLine(contact.DisplayName);
contactInfo.AppendLine(contact.FamilyName);
contactInfo.AppendLine(contact.Emails.FirstOrDefault().ToString());
contactInfo.AppendLine(contact.Phones.FirstOrDefault().ToString());
IsSingleContactRequired = true;
ContactInformation = contactInfo.ToString();
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
void OnDisplayAllContactsSelected()
{
}
#endregion
#region .Ctor
public ContactDisplayViewModel(IMvxNavigationService navigationService)
{
this.navigationService = navigationService;
}
#endregion
#region Override Methods
public override void Prepare()
{
base.Prepare();
IsSingleContactRequired = false;
}
#endregion
}
}
ContactDisplayView.xaml
<Button Grid.Row="0"
Grid.Column="0"
BackgroundColor="Transparent"
Text="Pick A Contact"
Command="{Binding SelectSingleContactCommand}"/>
<Label Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Text="{Binding ContactInformation}"
TextColor="DarkOrange"
IsVisible="{Binding IsSingleContactRequired}"/>
有没有人在尝试从任何此类 native/system 定义的应用程序导航回您的 Xamarin.Forms 应用程序时遇到此崩溃,或者一般来说,任何崩溃问题?
这是应用程序输出:
[Mono] Assembly Loader probing location: '/Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/sdks/out/android-x86-release/lib/Xamarin.Forms.Platform.Android.AppLinks.exe'.
[Mono] Assembly Loader probing location: '//Facades/Xamarin.Forms.Platform.Android.AppLinks.exe'.
[Mono] Requesting loading reference 13 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 13 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Legacy.Support.Core.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.Legacy.Support.Core.UI[0xe6461de0]: 2
[Mono] Requesting loading reference 3 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll asmctx DEFAULT, looking for Xamarin.AndroidX.DrawerLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Requesting loading reference 2 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.Legacy.Support.Core.UI.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
[Mono] Assembly Ref addref Xamarin.AndroidX.Legacy.Support.Core.UI[0xe6461de0] -> Java.Interop[0xe649f180]: 21
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_static_int_method_a'.
[Mono] Probing 'java_interop_jnienv_call_static_int_method_a'.
[Mono] Found as 'java_interop_jnienv_call_static_int_method_a'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_int_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_int_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_int_method_a'.
Thread started: #12
[HostConnection] HostConnection::get() New Host Connection established 0xc0ada410, tid 17005
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
[OpenGLRenderer] Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
[eglCodecCommon] setVertexArrayObject: set vao to 0 (0) 0 0
[EGL_emulation] eglCreateContext: 0xe650a220: maj 3 min 0 rcv 3
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[Gralloc3] mapper 3.x is not supported
[HostConnection] createUnique: call
[HostConnection] HostConnection::get() New Host Connection established 0xbe2518a0, tid 17005
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
[eglCodecCommon] allocate: Ask for block of size 0x1000
[eglCodecCommon] allocate: ioctl allocate returned offset 0x3ff24c000 size 0x2000
[Mono] Requesting loading reference 8 (of 9) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Vary.Core.Android.dll
[Mono] Loading reference 8 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Vary.Core.Android.dll asmctx DEFAULT, looking for Xamarin.Forms.Platform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Vary.Core.Android[0xe64538c0] -> Xamarin.Forms.Platform[0xe64639a0]: 3
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[eglCodecCommon] setVertexArrayObject: set vao to 0 (0) 1 0
[Mono] Requesting loading reference 11 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 11 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.Core[0xe6461900]: 7
[Mono] Requesting loading reference 16 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 16 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.AndroidX.SwipeRefreshLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040]: 2
[Mono] Requesting loading reference 3 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll
[Mono] Loading reference 3 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll asmctx DEFAULT, looking for Xamarin.AndroidX.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[Mono] Assembly Ref addref Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040] -> Xamarin.AndroidX.Core[0xe6461900]: 8
[Mono] Requesting loading reference 2 (of 4) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll
[Mono] Loading reference 2 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.AndroidX.SwipeRefreshLayout.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
[Mono] Assembly Ref addref Xamarin.AndroidX.SwipeRefreshLayout[0xe6463040] -> Java.Interop[0xe649f180]: 22
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_static_void_method_a'.
[Mono] Probing 'java_interop_jnienv_call_static_void_method_a'.
[Mono] Found as 'java_interop_jnienv_call_static_void_method_a'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_float_method_a'.
[Mono] Probing 'java_interop_jnienv_call_float_method_a'.
[Mono] Found as 'java_interop_jnienv_call_float_method_a'.
2021-03-05 03:03:56 [TRACE] (MvxForms) PresentationAttribute not found for ContactDisplayViewModel. Assuming ContentPage presentation
2021-03-05 03:03:56 [TRACE] (MvvmCross.Logging.MvxLog) No view model association found for candidate view MainActivity
2021-03-05 03:03:56 [TRACE] (MvvmCross.Logging.MvxLog) No view model association found for candidate view MainActivity
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_is_assignable_from'.
[Mono] Probing 'java_interop_jnienv_is_assignable_from'.
[Mono] Found as 'java_interop_jnienv_is_assignable_from'.
Resolved pending breakpoint at 'ContactDisplayViewModel.cs:67,1' to void Vary.Core.ViewModels.ContactDisplayViewModel.<OnSelectSingleContactSelected>d__13.MoveNext () [0x0015b].
[Mono] Requesting loading reference 5 (of 8) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Essentials.dll
[Mono] Loading reference 5 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Essentials.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Essentials[0xe64636a0] -> System.Core[0xe64a0140]: 9
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_object_field'.
[Mono] Probing 'java_interop_jnienv_get_object_field'.
[Mono] Found as 'java_interop_jnienv_get_object_field'.
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[EGL_emulation] eglMakeCurrent: 0xe650a220: ver 3 0 (tinfo 0xbe49d190)
[Mono] Requesting loading reference 12 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 12 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> System.Runtime.Serialization[0xe64a17c0]: 4
[Mono] DllImport searching in: 'libmono-native.so' ('./libmono-native.so').
[Mono] Searching for 'SystemNative_MkDir'.
[Mono] Probing 'SystemNative_MkDir'.
[Mono] Found as 'SystemNative_MkDir'.
[Mono] Requesting loading reference 21 (of 22) of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll
[Mono] Loading reference 21 of /storage/emulated/0/Android/data/com.vinayakjuneja.vary/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
[Mono] Assembly Ref addref Xamarin.Forms.Platform.Android[0xe64638e0] -> System.Xml[0xe64a16a0]: 7
[System] A resource failed to call close.
[System] A resource failed to call close.
全部代码:
public partial class MainPage : ContentPage, INotifyPropertyChanged
{
public Command SelectSingleContactCommand
{
get
{
return new Command(val =>
{
OnSelectSingleContactSelected();
});
}
}
private bool _isSingleContactRequired;
public bool IsSingleContactRequired
{
get
{
return _isSingleContactRequired;
}
set
{
if (_isSingleContactRequired != value)
{
_isSingleContactRequired = value;
NotifyPropertyChanged("IsSingleContactRequired");
}
}
}
private string _contactInformation;
public string ContactInformation
{
get
{
return _contactInformation;
}
set
{
if (_contactInformation != value)
{
_contactInformation = value;
NotifyPropertyChanged("ContactInformation");
}
}
}
public MainPage()
{
InitializeComponent();
this.BindingContext = this;
}
async void OnSelectSingleContactSelected()
{
try
{
var contact = await Contacts.PickContactAsync();
if (contact == null)
return;
var contactInfo = new StringBuilder();
contactInfo.AppendLine(contact.DisplayName);
contactInfo.AppendLine(contact.FamilyName);
contactInfo.AppendLine(contact.Emails.FirstOrDefault().ToString());
contactInfo.AppendLine(contact.Phones.FirstOrDefault().ToString());
IsSingleContactRequired = true;
ContactInformation = contactInfo.ToString();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
截图:
好吧,经过几个月的零星和频繁检查,经过大量的代码更改和大修,在 MainActivity 文件中发现了问题。
应从 MainActivity.cs 中删除“NoHistory = true”,否则一旦应用程序进入后台,它会删除您 activity 的所有历史记录,您将无法返回!因此应用程序崩溃(或者你可以说它进入后台,当你尝试从最近打开它时,你会得到第一个 activity/scree/view 模型)!
这么简单的解决这个缺陷,我哭笑不得!
P.S : 这解决了图像选取、文件选取和联系人选取的所有崩溃问题!
干杯!