partial void Uninitialize()
        {
            if (_activityLifecycleCallbacksListener != null)
            {
                var activity    = GetNavigationTarget <Activity>();
                var application = activity.Application;
                application.UnregisterActivityLifecycleCallbacks(_activityLifecycleCallbacksListener);

                _activityLifecycleCallbacksListener.ActivityPaused  -= OnActivityPaused;
                _activityLifecycleCallbacksListener.ActivityStopped -= OnActivityStopped;
                _activityLifecycleCallbacksListener.Dispose();
                _activityLifecycleCallbacksListener = null;
            }
        }
        partial void Initialize()
        {
            var activity    = GetNavigationTarget <Activity>();
            var application = activity.Application;

            if (application == null)
            {
                const string error = "To support navigation events in Android, Catel uses a custom ActivityLifecycleCallbacksListener. This requires an app instance though. Please make sure that the Android app contains an Application class.";
                Log.Error(error);

                throw new NotSupportedException(error);
            }

            _activityLifecycleCallbacksListener = new ActivityLifecycleCallbacksListener(activity);
            _activityLifecycleCallbacksListener.ActivityPaused  += OnActivityPaused;
            _activityLifecycleCallbacksListener.ActivityStopped += OnActivityStopped;

            application.RegisterActivityLifecycleCallbacks(_activityLifecycleCallbacksListener);

            // The first time, the general adapter will take care of this
            if (_isFirstTimeLoaded)
            {
                _isFirstTimeLoaded = false;
            }
            else
            {
                // Note: we don't subscribe to ActivityResumed because that equals the Loaded event. This adapter
                // is also created on the loaded
                _lastActivity = activity;

                var eventArgs = new NavigatedEventArgs(GetNavigationUri(activity), NavigationMode.New);
                RaiseNavigatedTo(eventArgs);
            }

            ContextHelper.CurrentContext = activity;
        }
        partial void Uninitialize()
        {
            if (_activityLifecycleCallbacksListener != null)
            {
                var activity = GetNavigationTarget<Activity>();
                var application = activity.Application;
                application.UnregisterActivityLifecycleCallbacks(_activityLifecycleCallbacksListener);

                _activityLifecycleCallbacksListener.ActivityPaused -= OnActivityPaused;
                _activityLifecycleCallbacksListener.ActivityStopped -= OnActivityStopped;
                _activityLifecycleCallbacksListener.Dispose();
                _activityLifecycleCallbacksListener = null;
            }
        }
        partial void Initialize()
        {
            var activity = GetNavigationTarget<Activity>();
            var application = activity.Application;
            if (application == null)
            {
                const string error = "To support navigation events in Android, Catel uses a custom ActivityLifecycleCallbacksListener. This requires an app instance though. Please make sure that the Android app contains an Application class.";
                Log.Error(error);

                throw new NotSupportedException(error);
            }

            _activityLifecycleCallbacksListener = new ActivityLifecycleCallbacksListener(activity);
            _activityLifecycleCallbacksListener.ActivityPaused += OnActivityPaused;
            _activityLifecycleCallbacksListener.ActivityStopped += OnActivityStopped;

            application.RegisterActivityLifecycleCallbacks(_activityLifecycleCallbacksListener);

            // The first time, the general adapter will take care of this
            if (_isFirstTimeLoaded)
            {
                _isFirstTimeLoaded = false;
            }
            else
            {
                // Note: we don't subscribe to ActivityResumed because that equals the Loaded event. This adapter
                // is also created on the loaded
                _lastActivity = activity;

                var eventArgs = new NavigatedEventArgs(GetNavigationUri(activity), NavigationMode.New);
                RaiseNavigatedTo(eventArgs);
            }

            ContextHelper.CurrentContext = activity;
        }