Load Xamarin Forms page from android notification

前端 未结 2 1516
南方客
南方客 2021-01-24 12:37

I am trying to load a Xamarin Forms page from an Android Notification. I am really lost on the android side of this, and most of my code has been pieced together from tutorials

2条回答
  •  孤独总比滥情好
    2021-01-24 13:10

    Problem is with your code Intent LoadPostPage = new Intent(Forms.Context, typeof(DroidToForms));.

    For Android platform of XF project, it only has one Activity, which is MainActivity, or pages of XF are rendered based on this MainActivity.

    So you may change you code like this:

    Intent intent = new Intent(context, typeof(MainActivity));
    intent.PutExtras(valuesForActivity);
    
    PendingIntent resultPendingIntent = PendingIntent.GetActivity(Xamarin.Forms.Forms.Context, 0, intent, PendingIntentFlags.OneShot);
    

    Then in your OnCreate method of MainActivity:

    //navigate to the page of PCL
    Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new PostPage());
    

    At last, as @Pratik suggested, if you want to create a native page/ view for Android platform, use PageRenderer or ViewRenderer to do so.

提交回复
热议问题