Saving user preferences in iOS using Xamarin

Xamarin provides a number of ways to save data in iOS using Local Storage. User preferences are generally stored in Library/Preferences/.
Xamarin iOs provides its built in mechanism i.e. instead of creating files directly in the directory it is suggested to use NSUserDefaults class to save data.

NSUserDefaults class provides its own built in mechanisms to save float, double, integers, Boolean and URL data. To save a custom object it should be converted to NSData object using NSUserDefaults.
Continue reading

Displaying alert dialog in Android using Xamarin

Alert dialog is a important part of any application. Conveying various information, error messages and even for taking confirmations from user can be done through alert dialog. Xamarin provides it’s own way of showing alert and conveying messages to the user.

Alerts in Xamarin are, an object of AlertDialog.Builder class, where AlertDialog is a subclass of Dialog class. Builder() is a method of AlertDialog class, which creates an alert dialog to display. We can add multiple buttons to this alert dialog. The builder takes the current context (Activity) and shows the Alert Box in the main thread(The UI thread). Continue reading

Relative layout design in Android using Xamarin

Xamarin provides different layout for designing the user interface in Android.
Some common ones being used are Relative Layout, Linear Layout, Grid Layout, Table Layout, Frame Layout etc. Most of them are understandable from their name itself. Here we will discuss about how to design using Relative Layout in Xamarin for Android.

As the name suggests, Relative Layout mainly makes use of the controls present in the Designer and places controls relatively to each other. The most important aspect of this design being the First element placed inside the tag. The places itself depending on the properties set for the children in the Relative Layout.
For example: Continue reading

Data passing in multiple screens from one activity to another using Xamarin in Android

Introduction :-
In this Article, we will see how to create multiple screens in Android using Xamarin and pass data between them.
Android applications consist of a set of loosely coupled screens, represented by Activity classes.
Since each Activity is essentially decoupled from others, there needs to be a way to launch them and optionally pass data to them. On Android this is accomplished using Intents.

Intents are the classes that describe a message, both what the desired action of the message is and a data payload to send along with it. They are commonly used within applications to launch Activities. To launch a new Activity, we create a new Intent, set the Context and the Activity class to launch and then tell the OS to handle the Intent, which launches the Activity. Continue reading

GPS Location Tracker using Xamarin

Mobile devices are smart enough to provide the geo-location coordinates by consuming the GPS API embedded inside.
Let’s get the geo-coordinates and a street address which is close to the location using Xamarin. In the below example I have demonstrated the same in Android environment.

Following are few steps

Step #1
After creating a new Xamarin Android app add some common permission in AssemblyInfo.cs

[assembly: UsesPermission(Manifest.Permission.Internet)]
[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)]
[assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)]

Step #2 Continue reading