jamesmontemagno / SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
MIT License
324 stars 80 forks source link

After reboot, loads old settings #135

Closed joakimmag closed 6 years ago

joakimmag commented 6 years ago

Bug Information

Version Number of Plugin: 3.1.1 Device Tested On: Nexus 5X Version of VS: 15.7.3 Version of Xamarin: 3.0.0 Versions of other things you are using:

Steps to reproduce the Behavior

  1. Apply Xam.Plugins.Settings as per documentation.
  2. Debug app. Perform code to save settings.
  3. Reboot phone.
  4. Debug app again.

Don't know if relevant but using a simple wrapper class and dependency injection with Prism.

Expected Behavior

Should load saved settings.

Actual Behavior

When close and reopen app, it loads the settings that were saved.

When reboot, loads old settings I saved a long time ago.

Deleted app and app data from phone settings. But still it fetches old settings.

Code snippet

App.xaml.cs

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterInstance<ISettings>(CrossSettings.Current);
    containerRegistry.RegisterSingleton<IProperties, Properties>();

Properties.cs

public Properties(ISettings settings)
{
    Settings = settings;
}
private ISettings Settings { get; }
private string GetValue(string key) => Settings.GetValueOrDefault(key, null);
private void SetValue(string key, string value) => Settings.AddOrUpdateValue(key, value);
public string Username
{
    get => GetValue(nameof(Username));
    set => SetValue(nameof(Username), value);
}

ConfigurationPageViewModel.cs

var u = Properties.Username; // Breakpoint. At this point it will read the correct value. After reboot, it will read the old value from a long time ago.
joakimmag commented 6 years ago

Update: After reset phone to factory settings, the problem is gone. It will save/retrieve as expected.