I'm trying to set up local settings so I can store data in my Windows Mobile 8 app. The first step I'm trying is:
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
Just having that in my code causes the app to fail when debugging on my device.
Any ideas why?
I have "using Windows.Storage;" set. The actual code doesn't throw up any errors.
I needed to use the IsolatedStorageSettings feature, as below:
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("test"))
{
settings.Add("test", urlText.Text);
}
else
{
settings["test"] = urlText.Text;
}
settings.Save();
Related
is there a way to check the app is installed for first time.I want this info cause i want to provide a small introduction session about the app features when user run the app for the first time.I want this to develop in windows phone 8.1 in c#
any help is welcome
Thank you
Maybe somethink like this:
On ApplicationStart:
Windows Phone 8:
if (!IsolatedStorageSettings.ApplicationSettings.Contains("FirstStart"))
{
//ShowTutorial
}else
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("FirstStart"))
{
settings.Add("FirstStart", "false");
}
//Start normal.
}
Here is a quickstart about Application Settings on Windows Phone: https://msdn.microsoft.com/en-us/library/windows/apps/jj714090%28v=vs.105%29.aspx
Windows Phone 8.1
On ApplicationStart:
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
if (localSettings.Values["FirstStart"] == null)
{
//ShowTutorial
}
else
{
localSettings.Values["FirstStart"] = "true";
}
https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localsettings.ASPx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
This question already has an answer here:
Recognize when is the app first launched WP8
(1 answer)
Closed 8 years ago.
I'm quite new on windows phone dev. I would like to detect when the user launches my app for the first time to display an explaination frame for example by calling :
if(firstLaunch)
showTheFrameToTheGuyBecauseHeLaunchedTheAppForTheFirstTime();
I would be sooooooo glad if someone could show us such a small script...
Thank you in advance guys !
I would recommend you to use the builtin applicationsettings.
const string settingsAppLaunched = "appLaunched";
public static bool IsFirstLaunch(){
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
return !(settings.Contains(settingsAppLaunched) && settings[settingsAppLaunched]);
}
public static bool Launched(){
if(IsFirstLaunch()){
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings.Add(settingsAppLaunched, true);
settings.Save();
}
}
//usage:
if(IsFirstLaunch()){
showTheFrameToTheGuyBecauseHeLaunchedTheAppForTheFirstTime();
Launched();
}
Microsoft Documentation about Settings in Windows Phone is available here.
You can simply use IsolatedStorageSettings.
if(!IsolatedStorageSettings.ApplicationSettings.Contains("first"))
{
// Do your stuff
IsolatedStorageSettings.ApplicationSettings["first"] = true;
IsolatedStorageSettings.ApplicationSettings.Save();
}
This code will do it.
After Updating A windows phone 8 app, will it keep the unused IsolatedStorage?
and if i change object saved in it, will it throw exceptions on users devices because of object changes doesn't saved under the key saved in the old version.
if so, how can i change/remove Edited/Unused IsolatedStorageSettings when i update a windows phone 8 application?
Isolated Storage data are preserved between updates, so it's the same IsolatedStorageSettings as in old version.
If you add/change objects in this way: settings["key"] = value; nothing wrong will happens after update. Also, you can check if some value exists or not before read it:
if (settings.Contains("key"))
{
string value = (string) settings["key"];
}
I couldnt find an answer to this question anywhere so I thought id ask here. Basically Iam following along with channel 9's tutorial on windows 8 phone for absolute beginners. Trying to follow along with the 'Around me' app tutorials. I create a Map element in the xaml. I create a geolocator object and attempt to set the view on my map to my current geocordinates. This doesnt work, the map view seems to show the location of microsofts headquarters in Redmond Washington each time I run the app. not Ireland, where it should be pointing? Below is my code which is all contained in the mainpage.xaml.cs
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
public async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(30));
var GeoCoorCenter = new GeoCoordinate(position.Coordinate.Latitude,position.Coordinate.Longitude);
AroundMeMap.SetView(GeoCoorCenter,17);
}
my code is the same as that used in the tutorial and it seems to work in that app. I also have the ID_CAP_LOCATION and ID_CAP_MAP set in the app manifest. Iam really not sure what the issue is here. Iam assuming its got something to do with the fact that Iam running the application in the emulator. If anyone can help me that would be great.
I've managed to run your code like this (basing on this answer and MSDN howto):
I've started the emulator, opened AdditionalTools -> Location and clicked somewhere on the Map (as my Location)
run Maps App - I see that shows the Location I've set, Close the Maps App
after that your App should point the right Location
As it's written at MSDN - it seems to be a bug which running Maps App fixes.
I'm using IsolatedStorageSettings class in my Windows Phone 7 project as a key-value store to remember user preferences and login credentials in my app.
The problem is, when I invoke Remove(string) method with the key and then I use Save() method to persist changes. Remove() method returns true, that means value is deleted. But when I try to get the value next time, I see that it is still there and not deleted.
Here's the code I use for deletion:
if (isolatedStore.Contains(key))
{
isolatedStore[key] = null;
}
bool del = isolatedStore.Remove(key);
isolatedStore.Save();
Here's how I get isolatedStorage instance:
private IsolatedStorageSettings isolatedStore =
IsolatedStorageSettings.ApplicationSettings;
Where do you think the problem is?
I found this block in the following link. I haven't tried to remove a key the way you're doing, though. http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/17514c94-1f59-47b4-bb78-99694bfbb6b2
public static void DeleteObject(string key)
{
IsolatedStorageSettings.ApplicationSettings.Remove(key);
}