I added a Splashscreen to the Application and called LoadMainPage() from the OnAppearing Method of the Page.Now everything is working Fine.
Problem Loading MainPage

Asgar Ali
86
Reputation points
I have this code to set the Mainpage in my application.
public async void LoadMainPage()
{
try
{
bool signedin = false;
signedin = Auth.IsUserSignedIn();
if (!signedin)
{
MainPage = new NavigationPage(new MainPage());
}
else if (signedin && !(await Firestore.IsUserRegistered()))
MainPage = new NavigationPage(new RegistrationPage());
else if (signedin && (await Firestore.IsUserRegistered()))
{
MainPage = new NavigationPage(new FlyoutPage1());
}
}
catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Error", ex.Message, "OK"); }
}
}
on starting the application the registrationpage and the flyoutpage fails to load properly.
it appears only when i tap the triple line icon on my phone wait for some time and tap the application again to launch it.
the code for Firestore.IsUserRegistered is as below
public async Task<bool> IsUserRegistered()
{
FirebaseFirestore collection = FirebaseFirestore.Instance;
string email = FirebaseAuth.Instance.CurrentUser.Email;
collection.Collection("User").WhereEqualTo("Email", email)
.Limit(1).Get()
.AddOnSuccessListener(this);
for (int i = 0; i < 25; i++)
{
await Task.Delay(100);
if (isregistered) break;
}
return isregistered;
}
public void OnSuccess(Java.Lang.Object result)
{
if (result == null) return;
else
{
var documents = (QuerySnapshot)result;
isregistered = ! documents.IsEmpty;
}
}
Developer technologies .NET Xamarin
5,380 questions