Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:56:16+00:00 2026-05-24T00:56:16+00:00

I am trying to serialize my game data. In case the user presses the

  • 0

I am trying to serialize my game data. In case the user presses the Windows button, everything should be saved. I know that we should override the OnExiting event in the game class. but am using the Game State Management , I want to serialize game data in my GamePlayScreen class. I did override the Serialize and DeSerialize methods, but they didnt work.

hers my code:

    public override void Serialize(Stream stream)
    {
        gameState.HumanPlayer = HumanPlayer;
        gameState.Player1 = AIPlayer1;
        gameState.Player2 = AIPlayer2;
        gameState.Player3 = AIPlayer3;
        XmlSerializer serializer = new XmlSerializer(typeof(GameState));
        serializer.Serialize(stream, gameState);
        base.Serialize(stream);
    }

    public override void Deserialize(Stream stream)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(GameState));
        gameState = (GameState)serializer.Deserialize(stream);

        if (gameState.HumanPlayer != null)
            HumanPlayer = gameState.HumanPlayer;
        if (gameState.Player1 != null)
            AIPlayer1 = gameState.Player1;
        if (gameState.Player2 != null)
            AIPlayer2 = gameState.Player2;
        if (gameState.Player3 != null)
            AIPlayer3 = gameState.Player3;

        base.Deserialize(stream);
    }

I tried to create my own IsolatedStorageFile instead of the provided stream object, but it didnt work.

I tried to write the same code in the Load and Unload event. it works fine there, but in case of pressing the back button. i need to serialize if the user pressed the windows button or the search button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:56:17+00:00Added an answer on May 24, 2026 at 12:56 am

    It looks like you need to handle the OnDeactivated and OnActivated events. Just do the same thing as is done in the OnExiting event and the Constructor. I would have thought the sample would do this as proper handling of tombstone/rehydrate is such a big thing for WP7, however it seems it has been neglected. Note that OnActivated is NOT called when the app is launched and OnDeactivated is NOT called when the app is closed manually or exited using the Back button.

    Note that Activated and Deactivated area also available as events on PhonApplicationServices.Current, along with Launching and Closing, which are ONLY called on actual open and exit situations.

    EDIT
    Ok, I take it back. OnDeactivated and OnActivated are not required. It seems that OnExiting is fired for both Deactivate and Exit scenarios. I downloaded the sample you linked (XNA4 WP7, not Mango version) and put this code into the GameplayScreen:

    public override void Serialize(System.IO.Stream stream)
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
        serializer.Serialize(stream, "Blah de blah blah");
        base.Serialize(stream);
    }
    
    public override void Deserialize(System.IO.Stream stream)
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
        string testStr = (string)serializer.Deserialize(stream);
    
        base.Deserialize(stream);
    }
    

    A break point shows that the Deserialize method is being hit functioning correctly, so your problem must be in how you apply your loaded data, or perhaps you’ve edited other code that has broken it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to serialize some data to xml in a way that can be
I'm trying to serialize a custom class that needs to use multiple elements of
I'm trying to serialize an object to XML that has a number of properties,
I have some XML that I am trying serialize like so: string Value =
I have been trying to serialize some json data in Silverlight. I am using
I'm trying to serialize a data structure and pass it to another report via
I am trying to serialize a class several of the data-members are Nullable objects,
I'm trying to serialize/deserialize a game scene for network sending/receiving and saving/loading from/to disk.
I am trying to serialize by following code var data = argsPerCall.ToArray(); var knownTypes
I am currently trying to serialize an object for a webproject that is hosted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.