Xamarin – walk-through – (Part 6)


Table layout


User Profile

Update Profile

Web View


Android Beam

Before you can send content between two devices with Android Beam, they must both be powered on and unlocked. If either device’s screen is off, or if either device is at its lock screen, Android Beam won’t work.

Fragments can be thought of as user interface modules. They let the developer divide up the user interface into isolated, reusable parts that can be run in separate Activities. At run time, the Activities themselves will decide which Fragments to use. In some regards, Fragments can be thought of as composite controls or as mini-Activities. They bundle up pieces of UI into reusable modules that can then be used independently by developers in Activities.


In general, Fragments should not implement a constructor or override the default constructor.

Fragments are available in the Android SDK starting with API level 11 (Android 3.0).

There are two ways that a Fragment may be hosted inside an Activity:

Declaratively – Fragments can be used declaratively within .axml layout files by using the <Fragment> tag.

Programmatically – Fragments can also be instantiated dynamically by using the FragmentManager class’s API.

Fragments that are declaratively added to an Activity are static and will remain on the Activity until it is destroyed; it is not possible to dynamically replace or remove such a Fragment during the lifetime of the Activity to which it is attached.

Fragment can save its state with a call to OnSaveInstanceState:

To help with managing Fragments, Android provides the FragmentManager class. Each Activity has an instance of Android.App.FragmentManager that will find or dynamically change its Fragments. Both Fragments and Activities reference the FragmentManager, so the same techniques are used to communicate back and forth between them.

Fragment subclasses

These subclasses are:

ListFragment – This Fragment is used to display a list of items bound to a datasource such as an array or a cursor.

DialogFragment – This Fragment is used as a wrapper around a dialog. The Fragment will display the dialog on top of its Activity.

PreferenceFragment – This Fragment is used to show Preference objects as lists.

To respond to user selections, an application must override the OnListItemClick method. The following example shows one such possibility:

The DialogFragment is a Fragment that is used to display a dialog object inside of a Fragment that will float on top of the Activity’s window. It is meant to replace the managed dialog APIs (starting in Android 3.0). The following screenshot shows an example of a DialogFragment:

The code for DialogFragment is:

Displaying a fragment

Setting up app-links in Android 6.0 involves two major steps:

Adding one or more intent-filters for the website URI’s – the intent filters guide Android in how to handle a URL click in a mobile browser.

Publishing a Digital Asset Links JSON file on the website – this is a file that is uploaded to a website and is used by Android to verify the relationship between the mobile app and the domain of the website. Without this, Android cannot install the app as the default handle for URI’s; the user must do so manually.

The following example shows how to use the IntentFilterAttribute to handle links from https://www.recipe-app.com/recipes and from http://www.recipe-app.com/recipes:

It is possible to register more than one SHA256 fingerprint to support different versions or builds of your application. This next assetlinks.json file is an example of registering multiple applications:

The Google Digital Asset Links website has an online tool that may assist with creating and testing the Digital Assets file.

Multi-window mode does not modify the Android activity lifecycle.

You can call the new Activity.InMultiWindow method to determine if your activity is in multi-window mode, and you can implement Activity.OnMultiWindowChanged so that Android can let you know when your activity goes into or out of multi-window mode.

The ConnectivityManager has been extended in Android N so that your app can check whether the user has enabled Data Saver so that your app can make an effort to limit its data usage when Data Saver is enabled.

Android 5.0 (Lollipop, Material Design) uses the new Android Runtime (ART) as the default runtime instead of Dalvik.

RecyclerView is similar to ListView, but it is better suited for large sets of views or lists with elements that change dynamically. Like ListView, you specify an adapter to access the underlying data set. However, unlike ListView, you use a layout manager to position items within RecyclerView. The layout manager also takes care of view recycling; it manages the reuse of item views that are no longer visible to the user.

Heads-up notifications are typically used for the following events:

A new next message
An incoming phone call
Low battery indication
An alarm

To select a directory subtree, you can build and send an Android.Intent.Action.OPEN_DOCUMENT_TREE intent. This intent causes the system to display all provider instances that support subtree selection; the user then browses and selects a directory.

To get paths to media directories on all shared storage devices, you call the new Android.Content.Context.GetExternalMediaDirs method.

Kitkat version check

To tell Android to wake an app during a specified time interval, call SetWindow on the AlarmManager, passing in the minimum and maximum time, in milliseconds, that can elapse before the app is woken, and the operation to perform at wakeup. The following code provides an example of an application that needs to be woken between a half hour and an hour from the time the window is set:

The following code example prints the contents of a WebView:

You can register the sensor and listen to changes in step count with the help of the ISensorEventListener interface, as illustrated by the code sample below:

Jelly bean

There is a new interface, Camera.IAutoFocusMoveCallback, which can be used to detect when the auto focus has started or stopped moving. An example of this new interface can be seen in the following snippet:

An example of how to use the MediaActionSound class can be seen in the following snippet:

ContentProviders expose their functionality through a Uri that is registered in the AndroidManifest.xml of the application that publishes the data. Android uses the Uri to search the system for the application that exposes a ContentProvider with that identifier. The Uri is a string, typically in a reverse-DNS format such as com.android.contacts/data.

Most ContentProvider implementations will be based on a SQLite database. The example database code in SimpleContentProvider/VegetableDatabase.cs creates a very simple two-column database, as shown:

OnCreate is a good place to get a reference to the LocationManager. It’s a good idea to keep the LocationManager as a class variable, so we can call it at various points in the Activity lifecycle. The code below requests location updates every 2000 milliseconds, and only when the location changes more than 1 metre:

Google Play Services is an add-on library that allows Android developers to take advantage of the most recent features from Google such as Google Maps Android API v2, Google Play In-app Billing v3, and Google Cloud Messaging.

Google play services check if enabled

Launch google maps

Add google maps into fragment

Move google maps camera

Markers demo

Zoom in and out buttons

Position Polar Bear Ground overlay

Street View

Adding a map fragment to and activity

keystore as a set of folders or a database/repository which contains certificates


Speech to text