使用意图过滤器启动时Xamarin.Android mvvmcross应用程序崩溃 [英] Xamarin.Android mvvmcross app crashes when launching with intent filter

查看:94
本文介绍了使用意图过滤器启动时Xamarin.Android mvvmcross应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When opening up the android application via a link, the android application crashes, with a NullReferenceExcetpion.

NREbase.OnCreate(bundle)方法中发生.基本类型为MvxFragmentCompatActivity.我也使用标准的MvxActivity进行了尝试.

The NRE happens in the base.OnCreate(bundle) method. The base is of type MvxFragmentCompatActivity. I have also tried this with a standard MvxActivity.

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

I have had a look at the following questions (but to no avail)

  • ViewModel null when Activity started from IntentFilter
  • Open MvvmCross app via link with data

活动

[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.access$800(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)

推荐答案

我认为这与以下内容有关:

I think this has to do with: https://github.com/MvvmCross/MvvmCross/issues/1192

尝试这样的事情:

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

    base.OnCreate(bundle);
}

这篇关于使用意图过滤器启动时Xamarin.Android mvvmcross应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆