简体   繁体   中英

How do I navigate from an Android Activity to a Xamarin Forms ContentPage?

I'm developing an application that uses an online payment. I open the link, for the payment, in a browser using: Device.OpenUri(Uri); . When the user has finished paying for his order he gets redirected to an Android Activity using a custom URL scheme:

[Activity(Label = "Urlentryclass", ScreenOrientation = ScreenOrientation.Portrait, Icon = "@drawable/icon",
        MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] {Android.Content.Intent.ActionView},
        DataScheme = "test",
        Categories = new[] {Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable})]
 public class Urlentryclass : FormsAppCompatActivity
...

How do I navigate to a certain Forms content page from this activity? I try to open a certain page using the following code example (It's done by using an Event Handler).

Navigation.PushAsync(new NavigationMenu(sisowStatus, modelStatus)).ConfigureAwait(false);

Followed by this.finish();

Hower, the view that's being showed is the last view that was opened before the browser shows. It seems that Navigation.PushAsync doesn't affect the view that's being showed. I've try PopAsync , PopToRootAsync but nothing seems to be working.

For those that are interested in the Event Handler, here it is:

public static class PaymentNavigationHelper
{
    public delegate void PaymentExecutedHandler(string sisowStatus, string orderStatus);
    public static event PaymentExecutedHandler OnPaymentExecuted;

    public static void PaymentExecuted(string sisowStatus, string orderStatus)
    {
        OnPaymentExecuted?.Invoke(sisowStatus, orderStatus);
    }
}

I'm subsribing to the event on the Content Page where I'm starting the payment:

 PaymentNavigationHelper.OnPaymentExecuted += (sisowStatus, modelStatus) =>
 {
     Navigation.PushAsync(new NavigationMenu(sisowStatus, modelStatus)).ConfigureAwait(false);
 };

In the activity which handles the payment url, the following code is being used:

PaymentNavigationHelper.PaymentExecuted(status, test.Model.FirstOrDefault().Status);

Any advice is highly appreciated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM