简体   繁体   English

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

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

Currently, I have a mobile application written in Xamarin.Android. 目前,我有一个用Xamarin.Android编写的移动应用程序。 Because there are constant HTTP requests going on in the app, what I'd like to do is keep the application active after closing it. 由于应用程序中不断发生HTTP请求,因此我想做的是在关闭应用程序后使其保持活动状态。

What I am looking at, is for example after you close the app, in the background it keeps sending HTTP requests, but there is a local notification where when you click it you can open the app. 我正在查看的内容是,例如,在关闭应用程序后,它在后台继续发送HTTP请求,但是有一个本地通知,当您单击它时就可以打开该应用程序。 There should be an explicit button for the exit which could be inside the application. 应该在应用程序内部有一个明确的退出按钮。 In more details, HTTP requests are sent on some interval in seconds. 更详细地讲,HTTP请求以秒为间隔发送。

So my end goal is to have the app constantly running, if it's in a background, then show a notification that it's still up and be able to close it (even from the background) only from the inside of the app. 因此,我的最终目标是使该应用程序始终处于运行状态(如果它在后台),然后显示通知它仍在运行,并且只能从应用程序内部关闭它(即使从后台)。

I couldn't find many resources specifically about this question and I am not quite sure what I can use in order to make this work. 我找不到有关该问题的大量资源,而且我不确定该如何使用。

Thanks in advance! 提前致谢!

According to the documentation what you're trying to do is supported: 根据文档,您正在尝试执行的操作受支持:

Sending notifications to the user 向用户发送通知

When a service is running, it can notify the user of events using Toast Notifications or Status Bar Notifications. 服务运行时,可以使用Toast通知或状态栏通知向用户通知事件。

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. 有关更多信息,请参见Toast Notifications或Status Bar Notifications开发人员指南。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM