void Background(SMS sms)
        {
            // Starting a new thread to do the workload of sending the sms
            new Thread(new ThreadStart(() =>
            {
                // Send sms
                VoipMsResponse response = SMSManager.SendSMS(sms);

                // An error ocured while sending sms... Show error message

                /*if (response.error != null) {
                 *      RunOnUiThread ( () => {
                 *              //response.error txtMessageStatus.Text;
                 *      });
                 * }*/

                // Save message to database, add it to the listview
                RunOnUiThread(() => {
                    var smsManager = new SMSManager(Database);
                    smsManager.AddMessage(sms);
                });
            }
                                       )).Start();
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            // Load contact infos
            string normalizedPhone = Intent.GetStringExtra("normalizedPhone");
            string message         = Intent.GetStringExtra("message");

            Contact contact = Contact.GetContactByPhone(normalizedPhone, this);

            // Get database instance
            Database = Manager.SharedInstance.GetDatabase(Tag.ToLower());

            var smsManager = new SMSManager(Database);
            var sms        = new SMS(normalizedPhone, message);

            // Create conversation document if not exist
            initConversation(sms);

            // If message comes from notification, add it to db
            string source = (string)Intent.GetStringExtra("source");

            if (source == "server")
            {
                sms.Source = source;
                smsManager.AddMessage(sms);
            }

            // Get previous messages
            // TODO : Filer messages to get only those from current conversation
            Query            = smsManager.GetQuery(sms.Target);
            Query.Completed += (sender, e) =>
                               Log.Verbose(Tag, e.ErrorInfo.ToString() ?? e.Rows.ToString());
            LiveQuery = Query.ToLiveQuery();

            SetContentView(Resource.Layout.Conversation);

            // Activate Back button in Action Bar
            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);

            // Rethrive layout fields
            TextView             newMessageText    = FindViewById <TextView> (Resource.Id.txtMessageBox);
            FloatingActionButton sendMessageButton = FindViewById <FloatingActionButton> (Resource.Id.btnSendMessage);
            LinearLayout         layout            = FindViewById <LinearLayout> (Resource.Id.mainLinearLayout);
            ListView             listView          = FindViewById <ListView>(Resource.Id.listViewMessages);

            // Set ActionBar to contact name
            this.Title = contact.DisplayName + " " + contact.NormalizedNumber;

            sendMessageButton.Click += (sender, e) => {
                sms.Message = newMessageText.Text;
                sms.Source  = "app";
                Background(sms);

                newMessageText.Text = "";
            };

            Database.Changed += (sender, e) => {
                var changes = e.Changes.ToList();
                foreach (DocumentChange change in changes)
                {
                    Log.Verbose(Tag, "Document " + change.DocumentId + " changed");
                }
            };

            // Bind listview adapyer to liveQuery
            listView.Adapter = new ListLiveQueryAdapter(this, LiveQuery);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            // Load contact infos
            string normalizedPhone = Intent.GetStringExtra("normalizedPhone");
            string message = Intent.GetStringExtra("message");

            Contact contact = Contact.GetContactByPhone(normalizedPhone, this);

            // Get database instance
            Database = Manager.SharedInstance.GetDatabase(Tag.ToLower());

            var smsManager = new SMSManager (Database);
            var sms = new SMS(normalizedPhone, message);

            // Create conversation document if not exist
            initConversation (sms);

            // If message comes from notification, add it to db
            string source = (string) Intent.GetStringExtra ("source");
            if (source == "server") {
                sms.Source = source;
                smsManager.AddMessage (sms);
            }

            // Get previous messages
            // TODO : Filer messages to get only those from current conversation
            Query = smsManager.GetQuery(sms.Target);
            Query.Completed += (sender, e) =>
                Log.Verbose(Tag, e.ErrorInfo.ToString() ?? e.Rows.ToString());
            LiveQuery = Query.ToLiveQuery();

            SetContentView (Resource.Layout.Conversation);

            // Activate Back button in Action Bar
            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);

            // Rethrive layout fields
            TextView newMessageText = FindViewById<TextView> (Resource.Id.txtMessageBox);
            FloatingActionButton sendMessageButton = FindViewById<FloatingActionButton> (Resource.Id.btnSendMessage);
            LinearLayout layout = FindViewById<LinearLayout> (Resource.Id.mainLinearLayout);
            ListView listView = FindViewById<ListView>(Resource.Id.listViewMessages);

            // Set ActionBar to contact name
            this.Title = contact.DisplayName + " " + contact.NormalizedNumber;

            sendMessageButton.Click += (sender, e) => {
                sms.Message = newMessageText.Text;
                sms.Source = "app";
                Background(sms);

                newMessageText.Text = "";
            };

            Database.Changed += (sender, e) => {
                var changes = e.Changes.ToList();
                foreach (DocumentChange change in changes) {
                    Log.Verbose(Tag, "Document " + change.DocumentId + " changed");
                }
            };

            // Bind listview adapyer to liveQuery
            listView.Adapter = new ListLiveQueryAdapter(this, LiveQuery);
        }
        void Background(SMS sms)
        {
            // Starting a new thread to do the workload of sending the sms
            new Thread(new ThreadStart(() =>
                {

                    // Send sms
                    VoipMsResponse response = SMSManager.SendSMS(sms);

                    // An error ocured while sending sms... Show error message
                    /*if (response.error != null) {
                        RunOnUiThread ( () => {
                            //response.error txtMessageStatus.Text;
                        });
                    }*/

                    // Save message to database, add it to the listview
                    RunOnUiThread ( () => {
                        var smsManager = new SMSManager (Database);
                        smsManager.AddMessage(sms);
                    });

                }
            )).Start();
        }