Search code examples
c#androidxamarin.formsonsaveinstancestate

Xamarin Forms PCL save instance state


I developed a Xamarin Forms application with a Portable Class Library. The orientation of my app is landscape. So whenever my screen goes black and I return to my app, the screen is 'reseted'. In my application, buttons change color by pressing them. Is there a possibility to save the state of the buttons, such as with the OnSaveInstanceState in Android?


Solution

  • Just follow this guide. It is pretty simple, just add

    [Activity (Label = "ActivityName", ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    

    above your activity :)