Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

Constructing a persistent and cross-platform settings system


Let's consider what we know from our previous examples:

  • All the system settings use a key and value system to store the names

  • The methods of entry and retrieval are different

  • Android cannot store all types of primitive (doubles are excluded), but it can store collections

From the PCL side, we need an interface to the main platform code:

public interface IUserSettings
{
  void SetSetting<T>(string name, T value);
  
  T GetSetting<T>(string name);
}

Unlike the example used with Android, we will not pass an enumeration as a second or third parameter.

After this, the platform implementations are required. The full source for this can be found in the Chapter 11 source code archive. I'll demonstrate how the implementation works for Android. To emulate a real setting, I've created the settings file and added some dummy data.

Creating the initial data

To start with, it's a good idea to start with creating a singleton. This is a single...