Exemplo n.º 1
0
        private async void CrystalApplication_EnteredBackground(object sender, EnteredBackgroundEventArgs e)
        {
            /// https://blogs.windows.com/buildingapps/2016/06/07/background-activity-with-the-single-process-model/
            /// Corresponds to EnteredBackground event. State should now be saved here.

            var deferral = e.GetDeferral();

            try
            {
                await PreservationManager.PreserveAsync(OnBackgroundingAsync());
            }
            catch (Exception)
            {
            }
            finally
            {
                deferral.Complete();
            }
        }
Exemplo n.º 2
0
        private async Task InitializeRootFrameAsync(IActivatedEventArgs e)
        {
            InitializeIoC();

            var rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                //rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                var navManager = new NavigationManager(this);

                var navService = new FrameNavigationService(rootFrame, navManager);
                navService.NavigationLevel = FrameLevel.One;

                navManager.RootNavigationService = navService;

                InitializeNavigation(navManager);
            }

            await OnApplicationInitializedAsync();

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //Resurrection!

                IStorageItem suspensionStateFileItem = await CrystalApplication.CrystalDataFolder.TryGetItemAsync(PreservationManager.SuspensionStateFileName);

                if (suspensionStateFileItem != null)
                {
                    StorageFile suspensionStateFile = (StorageFile)suspensionStateFileItem;

                    var eventArgs = new CrystalApplicationShouldRestoreEventArgs();
                    eventArgs.SuspensionFileDate = suspensionStateFile.DateCreated;
                    if (OnApplicationShouldRestore(eventArgs))
                    {
                        if (await PreservationManager.RestoreAsync() == true)
                        {
                            //navService.HandleTerminationReload();

                            //todo handle multiple windows in this case.

                            try
                            {
                                await suspensionStateFile.DeleteAsync();
                            }
                            catch (Exception)
                            {
                            }

                            IsRestored = true;

                            if (Restored != null)
                            {
                                Restored(this, EventArgs.Empty);
                            }
                        }
                    }
                }
            }



            // Ensure the current window is active
            //Window.Current.Activate();

            HandleBackNavigation();

            WindowManager.GetStatusManagerForCurrentView().Initialize();
        }