Patterns and best practices

In this section, we will have a look at two common patterns that are common to mobile applications and how to implement these usage scenarios in a platform agnostic manner.

Application preferences

Application preferences is a common scenario in mobile applications. In order to use the previously described property list on iOS and SharedPreferences on Android, a common dictionary interface is often the most appropriate approach. The interface would then be inherited on platform-specific projects and can be injected into the common library.

For a simple demonstration, we can define a simple interface that will retrieve and save string values. The code is as follows:

public interface ISettingsProvider { string this[string ...

Get Xamarin: Cross-Platform Mobile Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.