Wednesday, October 16, 2013

Xamarin: Saving and loading preferences in Android

Loading and saving preferences on Xamarin.Android should be done through the ISharedPreferences interface.

Here’s a quick sample to save preferences:

And another one to load them again:

2 comments:

Shruti Ramalingam said...
This comment has been removed by a blog administrator.
Advexp Components said...

You can use "Advexp.Settings Local" ( https://components.xamarin.com/view/advexp-settings-local ) to store any build-in or user-defined types and it collections in NSUserDefaults or KeyChain for iOS and SharedPreferences or KeyStore for Android. Interaction with settings occurs like with any variable or property in C#. This component support iOS, Android and PCL and it is unit tested. Also JSON serialization is supported. Ability to create app settings together with InAppSettingsKit ( https://components.xamarin.com/view/InAppSettingsKit ) and interaction with system Settings App for iOS. For more details see component`s examples.

Also you can use "Advexp.Settings Cloud" ( https://components.xamarin.com/view/advexp-settings-cloud ). This component has all Advexp.Settings Local functionality + ability to save settings to Amazon Cognito Sync cloud ( http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-sync.html ) and sync them across the different devices (iOS or Android)

Project site: https://bitbucket.org/advexp/component-advexp.settings

"Advexp.Settings Local" Xamarin component: https://components.xamarin.com/view/advexp-settings-local
"Advexp.Settings Cloud" Xamarin component: https://components.xamarin.com/view/advexp-settings-cloud

NuGet package “Advexp.Settings Local”:
https://www.nuget.org/packages/Advexp.Settings.Local
NuGet package “Advexp.Settings Cloud”, evaluation version:
https://www.nuget.org/packages/Advexp.Settings.Cloud.Evaluation