我正在使用Xamarin Rivets Components来创建一个深层链接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();
}
}
我需要有关如何启动深层链接应用程序的帮助。如果我在任何地方都错了,或者如果这个问题不清楚,请告诉我。
答案 0 :(得分:0)
您需要在MainActivity.cs上覆盖OnSavedInstance:
protected override void OnSaveInstanceState(Bundle outState)
{
//Yes, comment or delete the next line:
//base.OnSaveInstanceState(outState);
}