Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Why am I not seeing OnSaveInstanceState at the expected times?

EliasSimonEliasSimon USMember ✭✭

I'm figuring out how to save my Xamarin.Forms app's instance data. To make sure I understood when the override'd MainActivity methods are called, I implemented OnStop(), OnDestroy(), and OnSaveInstanceState() so that they simply call System.Diagnostics.Debug.WriteLine("methodName"), and then base.methodName;

Looking at the Output, though, I don't seem to be getting OnSaveInstanceState when I expect: it only gets called when the app is backgrounded, i.e. when I push the Overview or Home buttons. I do not get it when I push the Back button, though I still get the messages from OnStop and OnDestroy. Furthermore, when the screen rotates, I don't get any of the three events, and the app does not apparently get interrupted, even though there is supposedly some Activity destruction/creation that's supposed to happen.

What is going on? Is this some quirk of the Xamarin/VS debug environment? Has this been recently changed in Android and the documentation hasn't kept pace?

Using VS 2017, Samsung Galaxy S7 w/ Android 7

Best Answer

  • EliasSimonEliasSimon USMember ✭✭
    Accepted Answer

    Apparently, OnSaveInstanceState is not "part of the Activity Lifecycle". I don't care nearly as much about the other questions, so if a mod wants to delete this question, that would be fine with me.

Answers

  • EliasSimonEliasSimon USMember ✭✭
    Accepted Answer

    Apparently, OnSaveInstanceState is not "part of the Activity Lifecycle". I don't care nearly as much about the other questions, so if a mod wants to delete this question, that would be fine with me.

Sign In or Register to comment.