Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms properties are not saved in Release on Android

Tags:

I'm using Xamarin.Forms and Application.Current.Properties to persist user settings. I'm testing it on Android and it works fine

  • in Debug mode
  • in Release mode with linker configuration set to None

But it doesn't work with linker configuration set to SDK Assemblies Only. I'm testing by deploying an APK file directly to the device. Then I try to enter some settings and restart the application - and after restart all settings are lost. I'm not using complex data types, only string and bool.

I've found a workaround suggested here: https://forums.xamarin.com/discussion/30723/problems-with-application-current-properties. It suggests to ignore Xamarin.Forms.Core assembly, but it doesn't help.

When linker configuration is set to None, the APK size is huge (50mb!). I want to avoid that.

How can I persist application properties in Release build without setting linker configuration to None? Is it a known Xamarin bug?

like image 596
pfedotovsky Avatar asked Apr 11 '16 22:04

pfedotovsky


1 Answers

First of all, from xamarin docs(https://developer.xamarin.com/guides/xamarin-forms/working-with/application-class/#Properties_Dictionary) :

Note: the Properties dictionary can only serialize primitive types for storage. Attempting to store other types (such as List can fail silently).

If you want to store non-primitive type, you can, for example, convert it into JSON string using Newtonsoft.Json serializer, and then write to Properties(dont forget to deserialze when you read from Properties)


Btw, there is know bug: Properties didnt work in Release mode on Android. Suggest using Settings Plugin, it works pretty well.

like image 123
Flame239 Avatar answered Sep 28 '22 03:09

Flame239