Example #1
0
        public override void DidEnterBackground(UIApplication application)
        {
            ourTask = application.BeginBackgroundTask(delegate
            {    //this is the action that will run when the task expires
                if (ourTask != 0) //this check is because we want to avoid ending the same task twice
                {
                    application.EndBackgroundTask(ourTask); //end the task
                    ourTask = 0; //reset the id
                }
            });

            //we start an asynchronous operation
            //so that we make sure that DidEnterBackground
            //executes normally
            new System.Action(delegate
            {
                MonoGameGame.EnterBackground();

                //Since we are in an asynchronous method,
                //we have to make sure that EndBackgroundTask
                //will run on the application's main thread
                //or we might have unexpected behavior.
                application.BeginInvokeOnMainThread(delegate
                {
                        if (ourTask != 0) //same as above
                        {
                            application.EndBackgroundTask(ourTask);
                            ourTask = 0;
                        }
                   });
            }).BeginInvoke(null, null);
        }
		/// <Docs>Reference to the UIApplication that invoked this delegate method.</Docs>
		/// <remarks>Application are allocated approximately 5 seconds to complete this method. Application developers should use this
		/// time to save user data and tasks, and remove sensitive information from the screen.</remarks>
		/// <altmember cref="M:MonoTouch.UIKit.UIApplicationDelegate.WillEnterForeground"></altmember>
		/// <summary>
		/// Dids the enter background.
		/// </summary>
		/// <param name="application">Application.</param>
		public override void DidEnterBackground (UIApplication application)
		{
			Console.WriteLine("DidEnterBackground called...");

			// Ask iOS for additional background time and prepare upload.
			taskId = application.BeginBackgroundTask (delegate {
				if (taskId != 0) {
					application.EndBackgroundTask(taskId);
					taskId = 0;
				}
			});

			new System.Action (async delegate {

				await PrepareUpload();

				application.BeginInvokeOnMainThread(delegate {
					if (taskId != 0) {
						application.EndBackgroundTask(taskId);
						taskId = 0;
					}
				});

			}).BeginInvoke (null, null);
		}
Example #3
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication application)
        {
            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // app is no longer active, so reset the activation ID
            serviceHelper.ActivationId = null;

            // leave the user a notification if a prompt is currently running
            if (iOSSensusServiceHelper.PromptForInputsRunning)
                serviceHelper.IssueNotificationAsync("Please open to provide responses.", null);

            // save app state in background
            nint saveTaskId = application.BeginBackgroundTask(() =>
                {
                });

            serviceHelper.SaveAsync(() =>
                {
                    application.EndBackgroundTask(saveTaskId);
                });
        }