Beispiel #1
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            try
            {
                AppManager.Instance().RemoveActivity(this);
            }
            catch (Java.Lang.Exception ex)
            { }
        }
Beispiel #2
0
        public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
        {
            if (keyCode == Keycode.Back && e.Action == KeyEventActions.Down)
            {
                //这里解决Popup 弹出后,点击回退健时不能释放Popup问题
                Device.BeginInvokeOnMainThread(async() =>
                {
                    if (PopupNavigation.Instance.PopupStack.Count > 0)
                    {
                        await PopupNavigation.Instance.PopAllAsync();
                    }
                });

                if (!lastBackKeyDownTime.HasValue || (DateTime.Now - lastBackKeyDownTime.Value) > new TimeSpan(0, 0, 2))
                {
                    var actionPage = App.Current.MainPage;
                    if (actionPage?.Navigation != null && actionPage?.Navigation?.NavigationStack?.Count != 0)
                    {
                        actionPage = actionPage.Navigation.NavigationStack.Last();
                        if (null != actionPage)
                        {
                            if (actionPage is MainLayoutPage)
                            {
                                ToastUtils.ShowSingleToast("再按一次退出程序");

                                lastBackKeyDownTime = DateTime.Now;
                                return(true);
                            }
                            else if (actionPage is LoginPage)
                            {
                                MoveTaskToBack(true);
                                return(false);
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(async() =>
                                {
                                    await actionPage?.Navigation.PopAsync(true);
                                });
                            }
                        }
                    }
                }
                else
                {
                    //移除Activity
                    AppManager.Instance().ExitApp();
                }
                return(true);
            }
            return(base.OnKeyDown(keyCode, e));
        }
Beispiel #3
0
        public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
        {
            base.OnCreate(savedInstanceState, persistentState);
            try
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

                AppManager.Instance().AddActivity(this);
            }
            catch (Java.Lang.Exception ex)
            { }
        }