Using application settings in Windows Phone 7 apps
There are many settings that you can change within your smartphone to make it work better for you.
Join the DZone community and get the full member experience.Join For Free
Many applications have user input that should be somehow preserved in order to be restored when the application starts again. This includes preferences, URLs, general information, and whatnot. As in any other .NET application, a Windows Phone 7 application supports application settings.
Although the concept is similar, the way it is implemented is a bit different compared to regular console applications, for example. The way you are used to access them is through Properties.Settings.Default or through the Application Properties dialog. Both of these options are not available in a Windows Phone 7 application.
Instead, you should use IsolatedStorageSettings.ApplicationSettings, which is a member of the System.IO.IsolatedStorage namespace. The application settings are stored in a local application-scoped file that can, in fact, be created via IsolatedStorageFile.GetUserStoreForApplication().CreateFile(path).
This, however, would involve direct data manipulation and ApplicationSettings provides the necessary abstraction layer so that you can work with an existing structure without manually working with settings file contents.
Saving What You Have Already Done
Many applications on smartphones are getting smarter. That is to say that they are helping to log their user's input in such a way that allows them to retain the information that has already been entered into the app at some point. Many people don't realize just how much they can stand to benefit from using smart apps like this until they give it a try for themselves.
If you enter a few commands on your smartphone and then have to back out of the app that you are using for some reason, the application should be capable of storing those entries so that you can come back to them at a later time.
ApplicationSettings by itself is an instance of IEnumerable, so you can apply any action to it that applies to enumerable types.
The actual settings can be added and saved via the Add and Save methods, the latter being used to store the modified collection. Without it, once the application is closed, the settings are lost.
NOTE: Make sure you use unique names for each key. Otherwise, an ArgumentException will be thrown:
One important thing that should be mentioned about new application settings is that you can actually pass an object as the value for a specified key.
This makes it easier to store various class instances and one of the benefits it brings to the table is that you won’t have to serialize the instance manually. The object is restored in the same state it was passed to the Add method.
To retrieve saved settings, you can use two methods. First of all, you can use TryGetValue:
The advantage of this method is that no KeyNotFoundException will be thrown in case the key is not found. searchedValue will be empty, but at the same time, you won't have to deal with exception handling for this specific method.
The other way would be looking for the needed setting by directly passing the searched key:
Be aware of the fact that in case no key is found, a KeyNotFoundException will be thrown and you need to properly handle it in order to avoid an application crash.
You can also iterate through existing values and keys by using the Values and Keys ICollection-defined properties:
The setting removal is performed pretty much the same way as adding. However, this time you are only referencing the key by which the removed object is identified:
NOTE: No exception will be thrown if the key passed to the Remove method is not found, so you would have to make sure that the entered key is valid.
Changing Your Settings
The best thing that you can do to help yourself out on a Windows 7 Phone is to change the settings to where the apps are loaded up in such a way that they will automatically remember the information that you have entered into them.
This will allow you to keep some of the commands that you have entered without having to backtrack and go through all of your steps yet again. If you get your settings placed beforehand, then it shouldn't be a problem moving forward whenever you are using any of the apps.
Your App Data is Stored Deep in Your Phone
You may not realize it, but the app data that you use every day is stored deep inside your phone. The good news about this is that it means just a few tweaks to your settings is all that you should need to do in order to uncover the data that you are looking for.
That said, you will need to spend some time figuring out precisely where the data has been stored within your phone and how you are personally going to get access to it. No one said this process would be easy, but it is just something that you have to work through in order to get your desired outcome.
If you spend some time on it, you will probably be pleasantly surprised by how much progress you can make.
Can You Keep Your Data Safe From Other Phone Users?
There is a chance that you may have other people using your phone. It is quite common for people to allow their children to use their phones from time to time. Thus, you probably want to put some safeguards in place to make sure your children are not able to access every piece of information contained within your phone.
After all, there could be materials that they should not see or that need to be kept hidden from them.
Make sure you know how to use the proper child safety locks on your phone so that your children are not inadvertently exposed to materials that were not meant for them. You are not a bad person for having certain materials on your phone that are not kid-friendly.
Rather, you are a good person for wanting to keep them safe from those materials. There are many things in this world that children need to be shielded from, and you will want to make sure you are always keeping them safe when you allow them to use your phone.
There are plenty of things that you can do to help protect them, and one of those things is turning on the child locks so that your children are kept safe from the worst dangers of the Internet.
If that sounds like an ideal plan to you, then you need to get those set up on your phone right now. Your data can still linger on the phone for you, but you can at least keep that data to yourself and safe from your children’s eyes.
Opinions expressed by DZone contributors are their own.