Xamarin.Android mvvmcross 应用在使用 intent 过滤器启动时崩溃

Xamarin.Android mvvmcross app crashes when launching with intent filter

通过 link 打开 android 应用程序时,android 应用程序崩溃,并显示 NullReferenceExcetpion

NRE 发生在 base.OnCreate(bundle) 方法中。基数是 MvxFragmentCompatActivity 类型。我也用标准 MvxActivity.

试过这个

我看过以下问题(但无济于事)

Activity

[Activity(...)]
[IntentFilter(new[] { Intent.ActionView }, DataScheme = "https", DataHost = "my.link.com", DataPathPrefix = "/some/path/", Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })]
public class MyActivity : MvxFragmentCompatActivity<MyViewModel>
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        //Other code here (never reached when triggered by IntentFilter)
    }
}

堆栈跟踪

Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MvvmCross.Platform.Mvx.Resolve[TService] () <0x9dcd9978 + 0x00038> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current[T] () <0x9dcd9930 + 0x0001b> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current () <0x9dcd9910 + 0x0000f> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MvvmCross.Binding.Droid.Views.MvxLayoutInflater.Inflate (Int32 resource, Android.Views.ViewGroup root, Boolean attachToRoot) <0x9dcd7800 + 0x00033> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at Android.Views.LayoutInflater.n_Inflate_ILandroid_view_ViewGroup_Z (IntPtr jnienv, IntPtr native__this, Int32 resource, IntPtr native_root, Boolean attachToRoot) <0x9dcd7780 + 0x00063> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at (wrapper dynamic-method) System.Object:a2381224-dbcc-42b0-9aea-a687067e2004 (intptr,intptr,int,intptr,bool)
04-15 12:37:45.361 E/AndroidRuntime(26519): --- End of stack trace from previous location where exception was thrown ---
04-15 12:37:45.361 E/AndroidRuntime(26519):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x9dcdc6b8 + 0x0002b> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) <0x9dd046f0 + 0x000b3> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at Android.Support.V4.App.FragmentActivity.OnCreate (Android.OS.Bundle savedInstanceState) <0x9dcd6608 + 0x0014f> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MvvmCross.Droid.Support.V7.AppCompat.MvxEventSourceAppCompatActivity.OnCreate (Android.OS.Bundle bundle) <0x9dcd5850 + 0x00037> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at MyMobileApp.Droid.Activities.MyActivity.OnCreate (Android.OS.Bundle bundle) <0x9dcd5400 + 0x0001b> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) <0x9dcd5380 + 0x00057> in <filename unknown>:0 
04-15 12:37:45.361 E/AndroidRuntime(26519):   at (wrapper dynamic-method) System.Object:e50a07b6-601f-425e-bac2-dd61e65b301f (intptr,intptr,intptr)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at md5af86c8db51f1d1641c99147539ead00a.MyActivity.n_onCreate(Native Method)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at md5af86c8db51f1d1641c99147539ead00a.MyActivity.onCreate(MyActivity.java:43)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.Activity.performCreate(Activity.java:5990)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.ActivityThread.access0(ActivityThread.java:151)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.os.Looper.loop(Looper.java:135)
04-15 12:37:45.361 E/AndroidRuntime(26519):     at android.app.ActivityThread.main(ActivityThread.java:5254)

我认为这与以下内容有关:https://github.com/MvvmCross/MvvmCross/issues/1192

尝试这样的事情:

protected override void OnCreate(Bundle bundle)
{
    var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
    setup.EnsureInitialized();

    base.OnCreate(bundle);
}