如何在 Xamarin Forms 中在后台运行任务,即使应用程序被终止?

huangapple go评论78阅读模式
英文:

How do run a task in background and even if app terminated in xamarin forms?

问题

我需要在指定的时间运行一个任务,即使我的应用在Xamarin Forms(Android和iOS)中处于后台或终止状态。请建议我最佳的方法。

英文:

I need to run a task at a specified time even if my app in the background or terminated in Xamarin Forms(Android and iOS). Please suggest me the best way to do it.

答案1

得分: 1

如果您的应用程序处于后台状态,您可以运行后台服务,并在任何时候进行操作。
如果您的应用程序完全被终止,您无法执行任何操作。
唯一的方法是,如果您的应用程序被推送通知终止,当您的应用程序接收到通知时,您可以运行您的代码,但用户必须点击通知。

英文:

If your application is in the background you can run background services and let do whatever whenever,
If your application is totally terminated you cannot do anything.

The only way to do it if your application is terminated by push notification when your application receive the notification you can run your code but the user have to click on the notifications.

答案2

得分: 1

你无法编写代码,因为每个平台都有自己的后台服务方式和规则。你必须为每个平台创建服务。

我不想成为那个说“Google一下”的人,但有很多来自Xamarin的教程直接解释了后台操作。你有查看过吗?从Xamarin直接获取信息通常是开始的第一步。

文档 - https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/

视频 - https://www.youtube.com/watch?v=Z1YzyreS4-o

英文:

TYou can't write, Because each platform has their own way and rules for background services. You have to make services for each platform.

I don't want to be that guy that says "Google it" - but there are a number of tutorials directly from Xamarin that explain backgrounding. Have you looked? Getting your information directly from Xamarin is always the first place to start.

docs - https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/

video - https://www.youtube.com/watch?v=Z1YzyreS4-o

huangapple
  • 本文由 发表于 2020年1月4日 12:59:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59588031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定