Question

I have a page where user can enter his name and attach an image.

When returning from tombstoning state, is it mandatory for my app to restore the image too?

  1. Is it app certification requirement, something without which my app will not pass certification? Or is it a recommended pattern?

  2. same question in the case when I have a pivot for example, is it mandatory to save the index of selected pivot item and restore the selection when activating from tombstoning?

Not necessary: Is there a popular library \ framework to help me with tombstoning and serializing objects, images, etc?

Was it helpful?

Solution

According to the Technical certification requirements for Windows Phone , the only requirements are :

A Windows Phone app is deactivated when the user presses the Start button or if the device timeout causes the lock screen to engage. A Windows Phone app is also deactivated with it invokes a Launcher or Chooser API.

A Windows Phone OS 7.0 app is tombstoned (terminated) when it is deactivated. A Windows Phone OS 7.1 or higher app becomes Dormant when it is deactivated but can be terminated by the system when resource use policy causes it to tombstone.

When activated after termination, the app must meet the requirements in Section 5.2.1 – Launch time.

As the section 5.2.1 - "Launch time" only concerns startup performance and responsiveness, you don't have a certification requirement for your issue.

However, if the user enters data (attaches images, etc.) and let's say it answer a call, does some other stuff and get's back to the application and then the data he entered was lost... it surely won't appreciate it. That will look more like a defect/bug.

Concerning the serialization of your state, I recommend you to use binary serialization as the performance is at least 10x better than using Json, Xml or any other format.

Personally, I implement a custom interface, IBinarySerializable to my "state" related classes and use this BinaryWriter extensions class to help writing the serialization code:


using System.IO;

namespace MyCompany.Utilities
{
    public interface IBinarySerializable
    {
        void Write(BinaryWriter writer);
        void Read(BinaryReader reader);
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace MyCompany.Utilities
{
    public static class BinaryWriterExtensions
    {
        public static void Write<T>(this BinaryWriter writer, T value) where T : IBinarySerializable
        {
            if (value == null)
            {
                writer.Write(false);
                return;
            }

            writer.Write(true);
            value.Write(writer);
        }
    
        public static T Read<T>(this BinaryReader reader) where T : IBinarySerializable, new()
        {
            if (reader.ReadBoolean())
            {
                T result = new T();
                result.Read(reader);
                return result;
            }

            return default(T);
        }

        public static void WriteList<T>(this BinaryWriter writer, IList<T> list) where T : IBinarySerializable
        {
            if (list == null)
            {
                writer.Write(false);
                return;
            }

            writer.Write(true);
            writer.Write(list.Count);
            foreach (T item in list)
            {
                item.Write(writer);
            }
        }

        public static List<T> ReadList<T>(this BinaryReader reader) where T : IBinarySerializable, new()
        {
            bool hasValue = reader.ReadBoolean();
            if (hasValue)
            {
                int count = reader.ReadInt32();
                List<T> list = new List<T>(count);
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        T item = new T();
                        item.Read(reader);
                        list.Add(item);
                    }
                    return list;
                }
            }

            return null;
        }

        public static void WriteListOfString(this BinaryWriter writer, IList<string> list)
        {
            if (list == null)
            {
                writer.Write(false);
                return;
            }

            writer.Write(true);
            writer.Write(list.Count);
            foreach (string item in list)
            {
                writer.WriteSafeString(item);
            }
        }

        public static List<string> ReadListOfString(this BinaryReader reader)
        {
            bool hasValue = reader.ReadBoolean();
            if (hasValue)
            {
                int count = reader.ReadInt32();
                List<string> list = new List<string>(count);

                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        list.Add(reader.ReadSafeString());
                    }
                    return list;
                }
            }

            return null;
        }

        public static void WriteSafeString(this BinaryWriter writer, string value)
        {
            if (value == null)
            {
                writer.Write(false);
                return;
            }
        
            writer.Write(true);
            writer.Write(value);
        }

        public static string ReadSafeString(this BinaryReader reader)
        {
            bool hasValue = reader.ReadBoolean();
            if (hasValue)
                return reader.ReadString();

            return null;
        }

        public static void WriteDateTime(this BinaryWriter writer, DateTime value)
        {
            writer.Write(value.Ticks);
        }

        public static DateTime ReadDateTime(this BinaryReader reader)
        {
            var int64 = reader.ReadInt64();
            return new DateTime(int64);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top