Problem Loading MainPage

Asgar Ali 86 Reputation points
2022-09-29T15:05:05.827+00:00

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
{count} votes

1 answer

Sort by: Most helpful
  1. Asgar Ali 86 Reputation points
    2022-10-11T05:20:40.59+00:00

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.