Problem with using PushModalAsync on top of a custom rendered page in Android

The main page in my application requires a custom page renderer (and an activity). When the application launches, I initially need to display a login page (a simple Forms page). After some googling, it sounded like the recipe for this is to call PushModalAsync(new LoginPage()) in the OnAppearing method of my main page. The problem is that this doesn't work. The login page ends up behind the main page and not on top of it.

I'm fairly new to both Android and Xamarin, so I don't know exactly what's going on. That said, I could tell that the OnCreate() method of the main page's activity was actually firing after the constructor of the login page (rather than before). I assume this is a thread timing issue, related to the main page's renderer calling StartActivity() and the resulting delay before the OnCreate() method is actually called.

I've tried to work around the issue to no avail. For example, I tried calling PushModalAsync from the main page's activity's OnStart() method and even that didn't work (although it did result in the login page's constructor being called after the main page's OnCreate()). Any advice?

Thanks,

Bruce

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I think most of the Xamarin.Forms APIs use a single activity, which means if you show a new activity on top then anything you do in Xamarin.Forms will be in that original activity.

  • BruceElmoreBruceElmore USMember

    Any suggestions on how I should implement this given that Xamarin.Forms uses a single activity? Thanks!

  • adamkempadamkemp USInsider, Developer Group Leader mod

    You can make another Activity that hosts the Xamarin.Forms login page, Rather than using PusModalAsync you would instead use StartActivity, and the content of that activity (the "main page") would just be your login page.

Sign In or Register to comment.