保存逻辑删除的字符串值

本文关键字:字符串 删除 保存 | 更新日期: 2023-09-27 17:56:17

我目前正在开发一个适用于Windows Phone 7.1的应用程序,需要保存一些数据,以便在用户退出应用程序时。

该应用程序非常简单:主页是用户看到的第一件事,他们在其中选择四个购物中心之一。下一页询问他们把车停在哪里,并将其存储为 String 变量。最后一页加载该 String 变量,并向用户显示相关信息,以及自启动应用以来一直在进行的计时器。

我要保存的是用户输入的数据和用户离开应用程序时的计时器值,以便在再次启动它时,它会自动显示包含用户信息的最后一页。

我一直在玩生成的Application_Launching、激活等事件,但到目前为止无法正常工作。任何帮助将不胜感激。

编辑:这是我到目前为止的一些代码(没有引导我去任何地方)

    void LoadSettings()
    {
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        String mall;
        String level;
        String letter;
        String number;
        if (settings.TryGetValue<String>("mall", out mall))
        {
            _mall = mall;
        }
        if (settings.TryGetValue<String>("level", out level))
        {
            _level = level;
        }
        if (settings.TryGetValue<String>("mall", out letter))
        {
            _letter = letter;
        }
        if (settings.TryGetValue<String>("mall", out number))
        {
            _number = number;
        }
    }
    void SaveSettings()
    {
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        if (_mall != null)
        {
            settings["mall"] = (_mall as String);
            settings["level"] = (_level as String);
            settings["letter"] = (_letter as String);
            settings["number"] = (_number as String);
        }
    }

那是在我的 App.xaml.cs 类中

保存逻辑删除的字符串值

您必须查看应用程序.cs文件中的事件,但这也取决于您在应用程序激活、停用、关闭和启动时想要什么。

    // Code to execute when the application is launching (eg, from Start)
    // This code will not execute when the application is reactivated
    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
         LoadSettings();
    }
    // Code to execute when the application is activated (brought to foreground)
    // This code will not execute when the application is first launched
    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        if (e.IsApplicationInstancePreserved)
        {
            //The application was dormant and state was automatically preserved
        }
        else
        {
            LoadSettings();
        }
    }

    // Code to execute when the application is deactivated (sent to background)
    // This code will not execute when the application is closing
    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
         SaveSettings();
    }
    // Code to execute when the application is closing (eg, user hit Back)
    // This code will not execute when the application is deactivated
    private void Application_Closing(object sender, ClosingEventArgs e)
    {
        SaveSettings();
    }