简体   繁体   中英

Xamarin.Forms properties are not saved in Release on Android

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM