Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var content = _viewId.HasValue
                ? LayoutInflater.Inflate(_viewId.Value, null)
                : CreateDefaultView();

            if (content != null)
            {
                SetContentView(content);
            }

            if (Interlocked.Exchange(ref _state, StartedState) == DefaultState)
            {
                AndroidToolkitExtensions.SetCurrentActivity(this, false);
                if (AndroidBootstrapperBase.Current != null && AndroidBootstrapperBase.Current.IsInitialized)
                {
                    StartBootstrapperCallback(this);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(StartBootstrapperCallback, this);
                }
            }
        }
 public void OnActivityDestroyed(Activity activity)
 {
     if (IsAlive() && !(activity is IActivityView))
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, true);
     }
 }
 private void RaiseNew(Activity activity)
 {
     if (IsAlive() && !(activity is IActivityView) && _service.CurrentContent != activity)
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, false);
         _service.RaiseNavigated(activity, NavigationMode.New, null, null);
     }
 }
Example #4
0
 public void OnActivityDestroyed(Activity activity)
 {
     Interlocked.Decrement(ref _activityCounter);
     if (IsAlive() && !(activity is IActivityView))
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, true);
     }
 }
Example #5
0
        public override void OnDestroy(Action baseOnDestroy)
        {
            if (Tracer.TraceInformation)
            {
                Tracer.Info($"OnDestroy activity({Target})");
            }
            ServiceProvider.EventAggregator.Unsubscribe(this);
            Destroyed?.Invoke(Target, EventArgs.Empty);
            _view.ClearBindingsRecursively(true, true, AndroidToolkitExtensions.AggressiveViewCleanup);
            _view = null;

            if (_metadata != null)
            {
                _metadata.Clear();
                _metadata = null;
            }

            MenuTemplate.Clear(_menu);
            _menu = null;

            if (_menuInflater != null)
            {
                _menuInflater.Dispose();
                _menuInflater = null;
            }
            if (_layoutInflater != null)
            {
                _layoutInflater.Dispose();
                _layoutInflater = null;
            }
            ServiceProvider.Get <INavigationService>().OnDestroyActivity(Target, NavigationContext);
            base.OnDestroy(baseOnDestroy);
            ThreadPool.QueueUserWorkItem(state => AndroidToolkitExtensions.CleanupWeakReferences(true));
            AndroidToolkitExtensions.SetCurrentActivity(Target, true);
            Target.ClearBindings(false, true);
            OptionsItemSelected  = null;
            ActivityResult       = null;
            ConfigurationChanged = null;
            PostCreate           = null;
            BackPressing         = null;
            Created           = null;
            Started           = null;
            Paused            = null;
            SaveInstanceState = null;
            Stoped            = null;
            Restarted         = null;
            Resume            = null;
            Destroyed         = null;
        }
        public void OnResumeActivity(Activity activity, IDataContext context)
        {
            Should.NotBeNull(activity, nameof(activity));
            SetBackground(false, context);
            var prevContent = CurrentContent;

            if ((_newContext == null || IsFinishing(activity) || !_newContext.GetData(NavigationProvider.BringToFront)) && ReferenceEquals(activity, prevContent))
            {
                return;
            }
            var viewModel = activity.DataContext() as IViewModel;

            viewModel?.Settings.Metadata.Remove(NavigationProvider.BringToFront);
            AndroidToolkitExtensions.SetCurrentActivity(activity, false);
            var bundle = GetState(activity);

            if (bundle.ContainsKey(IsOpenedKey))
            {
                NavigationMode mode;
                IDataContext   ctx = _backContext;
                if (ctx != null || prevContent != null && IsFinishing(prevContent))
                {
                    mode         = NavigationMode.Back;
                    _backContext = null;
                }
                else
                {
                    ctx         = _newContext;
                    _newContext = null;
                    mode        = NavigationMode.Refresh;
                }
                RaiseNavigated(activity, mode, GetParameterFromIntent(activity.Intent), MergeContext(ctx, context));
            }
            else
            {
                bundle.PutBoolean(IsOpenedKey, true);
                var newContext = _newContext;
                _newContext = null;
                RaiseNavigated(activity, NavigationMode.New, GetParameterFromIntent(activity.Intent), MergeContext(newContext, context));
            }
        }
        public void OnResumeActivity(Activity activity, IDataContext context)
        {
            Should.NotBeNull(activity, nameof(activity));
            SetBackground(false, context);
            var prevContent = CurrentContent;

            if (ReferenceEquals(activity, prevContent))
            {
                return;
            }
            AndroidToolkitExtensions.SetCurrentActivity(activity, false);
            var bundle = GetState(activity);

            if (bundle.ContainsKey(IsOpenedKey))
            {
                NavigationMode mode;
                IDataContext   ctx = _backContext;
                if (ctx != null || prevContent != null && GetState(prevContent).ContainsKey(IsBackKey))
                {
                    mode         = NavigationMode.Back;
                    _backContext = null;
                }
                else
                {
                    ctx         = _newContext;
                    _newContext = null;
                    mode        = NavigationMode.Refresh;
                }
                RaiseNavigated(activity, mode, GetParameterFromIntent(activity.Intent), MergeContext(ctx, context));
            }
            else
            {
                bundle.PutBoolean(IsOpenedKey, true);
                var newContext = _newContext;
                _newContext = null;
                RaiseNavigated(activity, NavigationMode.New, GetParameterFromIntent(activity.Intent), MergeContext(newContext, context));
            }
        }
Example #8
0
        private static void StartBootstrapperCallback(object state)
        {
            var       activityBase = (SplashScreenActivityBase)state;
            Exception exception    = null;
            AndroidBootstrapperBase bootstrapper = null;

            try
            {
                bootstrapper = AndroidBootstrapperBase.GetOrCreateBootstrapper(activityBase.CreateBootstrapper);
                bootstrapper.Start();
            }
            catch (Exception e)
            {
                Tracer.Error(e.Flatten(true));
                exception = e;
            }
            finally
            {
                activityBase.OnBootstrapperStarted(bootstrapper, exception);
                AndroidToolkitExtensions.SetCurrentActivity(activityBase, true);
                _state = DefaultState;
            }
        }