2016-04-12 16 views
0

Xamarin Rivetsコンポーネントを使用して、深いリンクのAndroidアプリケーションを作成しています。 私はバックグラウンドで実行しているアプリケーションを持っているときに、アプリケーションを逆展開することができます。しかし、アプリケーションが起動されていないときは、例外がスローされます。Xamarin - Rivetsコンポーネント - アプリが起動していないときのDeepLink

私のコードは私のコードは下のように見えるリベットサンプル(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(); 


     } 
    } 

病気が深いリンクされたアプリケーションを起動する方法についてのヘルプが必要です。どこに間違っているのか、この質問が不明な場合は教えてください。

+0

あなたは私たちにスローされている正確な例外を告げ、そしてそのラインはそれを – Jason

+0

こんにちはジェイソン、例外を引き起こしている場合、それは本当に参考になります"onsaveinstancestateの後でアクションを実行できません"。 else部分は失敗します。それ以外の部分は、アプリが実行されていないときに実行されます。 –

答えて

0

あなたのMainActivity.csにOnSavedInstanceオーバーライドする必要があります:

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