Search code examples
phpxamarin.formslogout

How to save UserDetails before logging out in Xamarin.Forms (Android/IOS)


I don't know if the logout proces like the code beneath is correct but i would like to save all the user changes before a user hits the logout button. Is there a way to do this? Have you some example links or some php scripts that could do this?

private async void LogoutButton_Clicked(object sender, EventArgs e)
    {

        var res = await DisplayAlert("Would you like to logout?", null, "Yes", "Cancel");

        if(res == true)
        {
            Application.Current.MainPage = new NavigationPage(new MainPage()); //login page
        }
    }

Solution

  • You could look at Xamarin.Essentials: Preferences

    The Preferences class helps to store application preferences in a key/value store.

    you just need save data before you logout like:

    Preferences.Set("my_key", "my_value");
    

    and get the data :

    var myValue = Preferences.Get("my_key", "default_value");