【问题标题】:Xamarin - Rivets Component - DeepLink when the app is not startedXamarin - 铆钉组件 - 应用程序未启动时的 DeepLink
【发布时间】:2016-04-12 11:52:04
【问题描述】:

我正在使用 Xamarin Rivets 组件创建一个深层链接 Android 应用程序。 当我在后台运行应用程序时,我可以深度链接到应用程序。但是,当应用程序未启动时,它会引发异常。

我的代码来自铆钉样本 (https://components.xamarin.com/gettingstarted/rivets) 我的代码如下所示:

[Activity (Label = "ProductActivity")]
    [IntentFilter(new [] {Android.Content.Intent.ActionView },
        DataScheme= "mobisaveqaapp", //new[] {"mobisaveqaapp","mobisavedev"},
        DataHost="*",
        Categories=new [] { Android.Content.Intent.CategoryDefault })]
    public class ProductActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.ProductLayout);

            var id = "No Product ID Found";

            if (Intent.HasExtra ("al_applink_data")) {

                var appLinkData = Intent.GetStringExtra ("al_applink_data");

                var alUrl = new Rivets.AppLinkUrl (Intent.Data.ToString (), appLinkData);

                /*Todo: fetch Applinkdata target url,
                 * replace double slash with single slash,
                 * find the word offers,
                 * fecth the next index,
                 * start main activity,
                 * open all deals,
                 * open deal push async*/


                var offersVM = new OfferViewModel();
                var tableItems = offersVM.OfferCategories;
                Deal Localdeal = new Deal();

                foreach (var categories in tableItems)
                    if (categories.Key == "All Offers") {
                        Localdeal.DealName = categories.Key;
                        Localdeal.DealCount = categories.Value;
                        break;
                    }

                var url ="http://test:7070/nvtest/offers/664"; 

                url = url.Replace (":", "/");
                url = url.Replace ("//", "/");
                string[] words = url.Split('/');

                for(int i = 0;i<words.Length;i++) {
                    if (words [i].Trim ().ToLower () == "offers" && words [i + 1] != null) {
                        id = words [i + 1];
                        Device.BeginInvokeOnMainThread(() => {
                            if(App.Current != null && App.Current.MainPage != null && App.Current.MainPage.Navigation != null && App.Current.MainPage.Navigation.ModalStack.ToList ().Count > 0)
                            {
                                App.Current.MainPage.Navigation.PushModalAsync(new OffersSlideView(Localdeal, Convert.ToInt32(id)),false);  

                            }
                            else
                            {

                                App.Current.MainPage = new NavigationPage(new RootPageNew());
                            }
                        });
                    }

                }

            }

            this.Finish();


        }
    }

我需要有关如何启动深度链接应用程序的帮助。如果我在任何地方错了或者这个问题不清楚,请告诉我。

【问题讨论】:

  • 如果您告诉我们确切的异常被抛出,以及是哪一行导致它,这将非常有帮助
  • 嗨 Jason,例外情况是:“onsaveinstancestate 后无法执行操作”。 else 部分失败。其他部分在应用未运行时执行。

标签: c# xamarin xamarin.android xamarin.forms xamarin-studio


【解决方案1】:

您需要在 MainActivity.cs 上覆盖 OnSavedInstance:

protected override void OnSaveInstanceState(Bundle outState)
{
   //Yes, comment or delete the next line:
   //base.OnSaveInstanceState(outState);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多