开发者

What is the "Standard" way to store application state for windows mobile applications?

I am developing my fir开发者_JAVA技巧st windows mobile application and would like some guidance on the best way to save and restore application state between invocations of the applications.

My application will have a small number of properties, between 10 and 20, that I wish to store when I exit the application and restore when I restart.

My options for doing this would seem to be as follows :-

  1. Marshall in and out of XML
  2. Use a SQL Server 2005 Compact edition database
  3. Use a properties file with key-value pairs
  4. Use the registry.

What would generally be considered to be the standard/best practice way to do this?


You should definitively use a properties file (option 3). Not reason to make life harder for yourself by using any of the other options. This way you'll also be able to easily tamper with the file and check its correctness.

You could also store it using Google proto buffers, but that doesn't make it that easy anymore to tamper with the file!


If you want to be able to edit the settings while your application is not running, then the key=value file makes the most sense.

But if you don't care all that much about having your settings be a text file, a really quick and cheap way to do it is to put all of your settings into a struct and then just write that struct to a file when your app quits and read the struct back into memory when it starts.

An even slicker way to do this is to to use CreateFileMapping to map your settings file into memory in your applications. When you do this changes are automatically written back to the file whenever the struct is changed, so all you have to do is Close the mapping object when your application exits.

If you go this way, you should probably put a header on the structure so that you can detect version changes in the structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜