Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store the configuration values/settings in Windows Phone 8

Since there is no default configuration file In a WP8 app, what is the best way to store the configuration values, e.g. WCF service URL, User Name and Password. I want these values to be available and updatable when phone restarts and app is closed.

Thanks in advance.

like image 765
Kathir Avatar asked Feb 06 '13 06:02

Kathir


1 Answers

You should use IsolatedStorageSettings.ApplicationSettings.

Save a value:

IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Add("email", "[email protected]");
appSettings.Save();

Load a value:

IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
string val = (string)appSettings["email"];

See the MSDN tutorial here: How to: Store and Retrieve Application Settings Using Isolated Storage. It is a desktop Silverlight tutorial but it works the same way in Windows Phone.

EDIT:

Using IsolatedStorageSettings.ApplicationSettings can be problematic if your app uses background agents (thanks @RichardSzalay for the info).

If your agent only reads, IsolatedStorageSettings.ApplicationSettings with a Mutex is recommended.

Source: Background agent best practices for Windows Phone

like image 55
Olivier Payen Avatar answered Oct 08 '22 22:10

Olivier Payen