应用关闭时如何发送本地通知android?

问题描述:

我想知道在打开然后关闭应用程序后是否可以向设备发送本地通知.

I'd like to know if it's possible to send a local notification to the device when the app have been opened then closed.

当我的应用程序打开并且在后台时,它已经可以工作了.

It works already when my app is opened and when it's in the background.

谢谢

我想我还不够清楚:

即使该应用当时未运行,我也想在给定的时间发送本地通知.

I want to send a local notification at a given time even if the app is not running at that time.

本地通知"是指在我的应用中创建并通过使用AlarmManager和BroadcastReceiver发送的通知(android类).

By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver.

关闭->终止了我的应用程序进程

closed -> killed the process of my app

大多数杀死[您的]应用程序的过程"的方式都将使您的警报保持完整,因此,无论您计划什么,都将保持计划,并在设置时继续被调用.

Most means of "killed the process of [your] app" will leave your alarms intact, and so whatever you have scheduled will remain scheduled and keep being invoked as you set up.

即使该应用当时未运行,我也想在给定的时间发送本地通知.

I want to send a local notification at a given time even if the app is not running at that time.

同样,AlarmManager并不取决于您所处的进程,只要它可以调用您提供的PendingIntent.只要您正在使用的BroadcastReceiver在清单中注册(而不是通过registerReceiver()),它就可以正常工作.

Again, AlarmManager is not dependent upon your process being around, so long as it can invoke the PendingIntent that you supply. So long as the BroadcastReceiver you are using is registered in the manifest (and not via registerReceiver()), it should work fine.

如果用户(通常通过设置"应用程序)强制停止您的应用程序,则不仅不会调用您的警报,而且代码也永远不会再次运行,直到明确启动您的应用程序(通常是用户点击在启动器中的图标上).您对此无能为力.

If the user force-stops your app -- usually via the Settings app -- then not only will your alarms not be invoked, but your code will never run again, until something explicitly starts up your app (usually the user tapping on your icon in the launcher). There is nothing that you can do about this.

当您完全理解并且英语不是您的母语时,很难解释事情

it's hard to explain things when you do understand fully and when english is not your native language

许多Android开发人员支持网站,提供了多种语言.