c# - 在 Xamarin 中使用isolatedStorage

标签 c# xamarin.android isolatedstorage

我正在尝试使用 Xamarin 的 Mono 东西(MonoTouch 和 MonoDroid)构建一个应用程序。我正在尝试编写一些代码,允许我将内容放入本地存储中。由于具有 Windows Phone 背景,我认为这也是 Xamarin 世界中推荐的方法。在 Windows Phone 上,我会执行以下操作:

IsolatedStorageSettings clientStorage = IsolatedStorageSettings.ApplicationSettings;
if (clientStorage != null)
{
  if (clientStorage.Contains("myKey"))
    clientStorage["myKey"] = value;
  else
    clientStorage.Add("myKey", value);
  clientStorage.Save();
}

虽然 Xamarin 堆栈提供 System.IO.IsolatedStorage,但它不提供 IsolatedStorageSettings 类。现在,我感到困惑,找不到例子。我的问题是,如何在 Mono 应用程序中的独立存储中添加值?

谢谢

最佳答案

IsolatedStorageSettings is not implemented in the mobile solutions 。看起来可以根据该帖子添加它,但它必须是自定义实现。

不过,一般来说,您还有其他一些选择。

  • 使用 native 支持的机制。 Android:共享首选项(example) 。 iOS:NS用户设置 (example) .
  • 使用 JSON 或 XML 将设置存储在序列化对象中,然后 当您需要访问该对象时,反序列化该对象。这里将 可能是一个很好的快速但肮脏的选择,但不推荐。
  • 使用 SQLite 数据库来存储您的设置。这将是一个更 跨平台选项,可能是最推荐的选项。

关于c# - 在 Xamarin 中使用isolatedStorage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426060/

相关文章:

c# - 调试时不要中断

c# - ASP.NET 核心 3.0 : The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace

c# - 如何更改 EmguCV 中的反转帧?

c# - 如何在 monodroid 中删除用于编辑文本的 TextChangedListener

silverlight - 一台机器上两个Silverlight应用程序可以共享IsolatedStorage吗?

c# - 如何捕获网络服务的原始请求/响应

android - 将 webView.AddJavascriptInterface 与 MonoDroid 一起使用

xamarin - 处理 Xamarin PCL 项目中的文件

c# - 在 Windows Phone 7 上从独立存储打开 JPEG 时出现问题

c# - isolatedStorageFile.GetLastAccessTime 在 wp7 上崩溃