How can I save some user data locally on my Xamarin Forms app?

Pure.Krome picture Pure.Krome · Jul 27, 2015 · Viewed 64.4k times · Source

I have a simple Xamarin Forms app. I've now got a simple POCO object (eg. User instance or an list of the most recent tweets or orders or whatever).

How can I store this object locally to the device? Lets imagine I serialize it as JSON.

Also, how secure is this data? Is it part of Keychains, etc? Auto backed up?

cheers!

Answer

Will Decker picture Will Decker · Jul 27, 2015

You have a couple options.

  1. SQLite. This option is cross-platform and works well if you have a lot of data. You get the added bonus of transaction support and async support as well. EDIT: In the past I suggested using SQLite.Net-PCL. Due to issues involving Android 7.0 support (and an apparent sunsetting of support) I now recommend making use of the project that was originally forked from: sqlite-net
  2. Local storage. There's a great nuget that supports cross-platform storage. For more information see PCLStorage
  3. There's also Application.Current.Properties implemented in Xamarin.Forms that allow simple Key-Value pairs of data.

I think you'll have to investigate and find out which route serves your needs best.

As far as security, that depends on where you put your data on each device. Android stores app data in a secure app folder by default (not all that secure if you're rooted). iOS has several different folders for data storage based on different needs. Read more here: iOS Data Storage