Xamarin.Android - 通过本地通知关闭应用后,让应用在后台运行

Xamarin.Android - Keep the app working in background after closing it with a local notification

目前,我有一个用 Xamarin.Android 编写的移动应用程序。因为应用程序中不断发出 HTTP 请求,所以我想做的是在关闭应用程序后保持应用程序处于活动状态。

我正在看的是,例如,在您关闭应用程序后,它会在后台不断发送 HTTP 请求,但是有一个本地通知,当您单击它时,您可以打开该应用程序。应用程序内部应该有一个明确的退出按钮。更详细地说,HTTP 请求以秒为单位按一定间隔发送。

所以我的最终目标是让应用程序持续运行 运行,如果它在后台,则显示它仍在运行的通知,并且只能从在应用程序内部。

我找不到很多专门关于这个问题的资源,而且我不太确定我可以使用什么来完成这项工作。

提前致谢!

根据文档,支持您尝试执行的操作:

Sending notifications to the user

When a service is running, it can notify the user of events using Toast Notifications or Status Bar Notifications.

A toast notification is a message that appears on the surface of the current window for only a moment before disappearing. A status bar notification provides an icon in the status bar with a message, which the user can select in order to take an action (such as start an activity).

Usually, a status bar notification is the best technique to use when background work such as a file download has completed, and the user can now act on it. When the user selects the notification from the expanded view, the notification can start an activity (such as to display the downloaded file).

See the Toast Notifications or Status Bar Notifications developer guides for more information.

参考:https://developer.android.com/guide/components/services
参考:https://developer.android.com/guide/components/processes-and-threads