2016-04-12 30 views
0

我使用Xamarin鉚釘組件創建深層鏈接android應用程序。 我能夠深入鏈接到應用程序,當我有應用程序在後臺運行。但是,當應用程序未啓動時,會引發異常。 (https://components.xamarin.com/gettingstarted/rivets)我的代碼如下Xamarin - 鉚釘組件 - 應用程序未啓動時的DeepLink

我的代碼是從鉚釘樣本導出爲下:如何開始的深層鏈接的應用程序

[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(); 


     } 
    } 

生病需要幫助。如果我在任何地方或者如果這個問題不清楚,請告訴我。

+0

這將是非常有益的,如果你告訴我們,被拋出的確切異常,併線造成的呢 – Jason

+0

嗨傑森,異常是:「不能在onsaveinstancestate之後執行操作」。其他部分失敗。其他部分在應用程序未運行時執行。 –

回答

0

你需要重寫OnSavedInstance您MainActivity.cs:

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