本文整理汇总了C#中UIApplication.EndBackgroundTask方法的典型用法代码示例。如果您正苦于以下问题:C# UIApplication.EndBackgroundTask方法的具体用法?C# UIApplication.EndBackgroundTask怎么用?C# UIApplication.EndBackgroundTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIApplication
的用法示例。
在下文中一共展示了UIApplication.EndBackgroundTask方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DidEnterBackground
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);
}
示例2: DidEnterBackground
/// <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);
}
示例3: DidEnterBackground
// 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);
});
}