Navigate to main page instead of Login page

DarshanJSDarshanJS USMember ✭✭✭

@AlessandroCaliaro, @NMackay,@FredyWenger,@AdamP,@MihaMarkic

Hi guys,

User successfully logged into app for the first time.
And when he want open to visit app for the second time i want to navigate directly to main page i don't want show Login page again
How to achieve that

please help me

Best Answers

  • DarshanJSDarshanJS USMember ✭✭✭
    Accepted Answer

    And i have this in settings
    @AlessandroCaliaro, @NMackay,
    Tools => Options => Xamarin => Android => Check "Preserve application data/cache on device between deploys"

Answers

  • NMackayNMackay GBInsider, University ✭✭✭✭✭

    Just set the main page at startup to be the Dashboard/Start page rather than the login page if a session key exists.

  • DarshanJSDarshanJS USMember ✭✭✭

    Thanks @AlessandroCaliaro, @NMackay, sure i will try both

  • seanydaseanyda GBMember ✭✭✭✭✭
    edited September 28

    What I do is write to a local file and store the state of the login.

    Use the below methods in the platform specific projects

    public string PersonalFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        public void WriteLocalFile(string FileName, string Data)
                {
                    string filePath = Path.Combine(PersonalFolderPath, FileName);
                    File.WriteAllText(filePath, Data);
                }
    
                public string LoadLocalFile(string FileName)
                {
                    string filePath = Path.Combine(PersonalFolderPath, FileName);
                    if (File.Exists(filePath)) return File.ReadAllText(filePath);
                    return "File Doesn't Exist";
                }
    

    If the app is closed or updated this information is stored. Use the DependencyService to access the methods and an interface in the PCL.

  • DarshanJSDarshanJS USMember ✭✭✭

    Hi guys,

    This worked for me.

    In login page,
    Clslogin login = new Clslogin();
    login.key = password;
    App.Current.Properties.Add("savedProp", password);
    await App.Current.SavePropertiesAsync();

                       and while restarting the app 
    
            if (Application.Current.Properties.ContainsKey("savedProp"))
                    {
                        MainPage = new Contents.MainAppPage();
    
                    }
                    else
                    {
                        MainPage = new Contents.Loginpage();
    
                    }
    

    Thank you so much @AlessandroCaliaro, @NMackay,

  • DarshanJSDarshanJS USMember ✭✭✭
    Accepted Answer

    And i have this in settings
    @AlessandroCaliaro, @NMackay,
    Tools => Options => Xamarin => Android => Check "Preserve application data/cache on device between deploys"

Sign In or Register to comment.