/// <inheritdoc/> protected override void OnStart() { base.OnStart(); Ioc.Reset(); Startup.InitializeApplication(this); INavigationService navigation = Ioc.GetOrCreate <INavigationService>(); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); if (IsStartedBySendIntent()) { // Another app sent content to SilentNotes navigation.Navigate(ControllerNames.Note, ControllerParameters.SendToSilentnotesText, GetSendIntentText()); } else if (IsStartedByOAuthRedirectIndent(storyBoardService)) { if (storyBoardService.ActiveStory is SynchronizationStoryBoard synchronizationStory) { // Create a copy of the active story, which uses the Ioc of this new process storyBoardService.ActiveStory = new SynchronizationStoryBoard(synchronizationStory); storyBoardService.ActiveStory.ContinueWith(SynchronizationStoryStepId.HandleOAuthRedirect.ToInt()); } } else { // Normal startup navigation.Navigate(ControllerNames.NoteRepository); IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtStartup(); // no awaiting, run in background } }
/// <summary> /// Invoked when application execution is being suspended. Application state is saved /// without knowing whether the application will be terminated or resumed with the contents /// of memory still intact. /// </summary> /// <param name="sender">The source of the suspend request.</param> /// <param name="e">Details about the suspend request.</param> private async void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); try { // The synchronisation with the online storage needs possibly more time than // granted with e.SuspendingOperation.Deadline, so we request an extended session using (var extendedSession = new ExtendedExecutionSession()) { bool gotExtendedSession; extendedSession.Reason = ExtendedExecutionReason.SavingData; extendedSession.Description = "Synchronization with the online storage."; extendedSession.Revoked += (object s, ExtendedExecutionRevokedEventArgs a) => gotExtendedSession = false; gotExtendedSession = await extendedSession.RequestExtensionAsync() == ExtendedExecutionResult.Allowed; // Save application state and stop any background activity INavigationService navigationService = Ioc.GetOrCreate <INavigationService>(); navigationService.CurrentController?.StoreUnsavedData(); if (gotExtendedSession) { IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); await syncService.SynchronizeAtShutdown(); } } } catch { } deferral.Complete(); }
/// <summary> /// The OnStart() and OnNewIntent() methods have no guaranteed order, so we do all the /// work for starting up the app here, this is guaranteed to be called after them. /// </summary> protected override void OnResume() { base.OnResume(); // Turn on the view again, see OnPause(). if (_webView.Visibility != ViewStates.Visible) { _webView.Visibility = ViewStates.Visible; } INavigationService navigationService = Ioc.GetOrCreate <INavigationService>(); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); if (!string.IsNullOrEmpty(_actionSendParameter)) { // Create new note and show it IRepositoryStorageService repositoryStorageService = Ioc.GetOrCreate <IRepositoryStorageService>(); ISettingsService settingsService = Ioc.GetOrCreate <ISettingsService>(); repositoryStorageService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); NoteModel note = new NoteModel { BackgroundColorHex = settingsService.LoadSettingsOrDefault().DefaultNoteColorHex, HtmlContent = _actionSendParameter, }; noteRepository.Notes.Insert(0, note); repositoryStorageService.TrySaveRepository(noteRepository); _actionSendParameter = null; // create the note only once navigationService.Navigate(new Navigation(ControllerNames.Note, ControllerParameters.NoteId, note.Id.ToString())); } else if (IsStartedByOAuthRedirectIndent(storyBoardService)) { if (storyBoardService.ActiveStory is SynchronizationStoryBoard synchronizationStory) { // Create a copy of the active story, which uses the Ioc of this new process storyBoardService.ActiveStory = new SynchronizationStoryBoard(synchronizationStory); storyBoardService.ActiveStory.ContinueWith(SynchronizationStoryStepId.HandleOAuthRedirect); } } else { // Normal startup if (CanStartupWithLastNavigation(_lastNavigation)) { navigationService.Navigate(_lastNavigation); } else { navigationService.Navigate(new Navigation(ControllerNames.NoteRepository)); } IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtStartup(); // no awaiting, run in background } }
/// <inheritdoc/> protected override void OnStop() { // The synchronization continues when we do not await it, even if another app became // active in the meantime. As long as the user doesn't swipe away the app from the // "recent apps", it can finish the job, that's exactly what we need. // Tested with Android 5.0, 8.1 IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtShutdown(); base.OnStop(); }
/// <inheritdoc/> protected override void OnStop() { INavigationService navigationService = Ioc.GetOrCreate <INavigationService>(); navigationService.CurrentController?.StoreUnsavedData(); navigationService.CurrentController?.Dispose(); // The synchronization continues when we do not await it, even if another app became // active in the meantime. As long as the user doesn't swipe away the app from the // "recent apps", it can finish the job, that's exactly what we need. // Tested with Android 5.0, 8.1 IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtShutdown(); // We can safely clear the Ioc, it will be rebuilt in the OnStart event. The still // running syncService doesn't need Ioc, got its required services in the constructor. Ioc.Reset(); base.OnStop(); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame 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; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); } IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtStartup(); // no awaiting, run in background }