public override void OnDestroy()
        {
            // We need to shut things down.
            //Log.Info(Tag, "OnDestroy: The started service is shutting down.");

            // Remove the notification from the status bar.
            NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Cancel(ServiceRunningNotificationId);

            if (_wakeLockCpu != null)
            {
                try
                {
                    _wakeLockCpu.Release();
                    _wakeLockCpu.Dispose();
                }
                catch (Exception)
                {
                    // ignored
                }
                _wakeLockCpu = null;
            }

            _activityCommon.Dispose();
            _activityCommon = null;
            _isStarted      = false;
            base.OnDestroy();
        }
        public void SetService(AndroidSensusService service)
        {
            _service = service;

            if (_service == null)
            {
                if (_connectivityManager != null)
                {
                    _connectivityManager.Dispose();
                    _connectivityManager = null;
                }

                if (_notificationManager != null)
                {
                    _notificationManager.Dispose();
                    _notificationManager = null;
                }

                if (_textToSpeech != null)
                {
                    _textToSpeech.Dispose();
                    _textToSpeech = null;
                }

                if (_wakeLock != null)
                {
                    _wakeLock.Dispose();
                    _wakeLock = null;
                }
            }
            else
            {
                _connectivityManager      = _service.GetSystemService(Context.ConnectivityService) as ConnectivityManager;
                _notificationManager      = _service.GetSystemService(Context.NotificationService) as NotificationManager;
                _textToSpeech             = new AndroidTextToSpeech(_service);
                _wakeLock                 = (_service.GetSystemService(Context.PowerService) as PowerManager).NewWakeLock(WakeLockFlags.Partial, "SENSUS");
                _wakeLockAcquisitionCount = 0;
                _deviceId                 = Settings.Secure.GetString(_service.ContentResolver, Settings.Secure.AndroidId);
            }
        }