How to send local notification android when app is

2019-01-29 06:43发布

问题:

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.

Thanks

Edit : I think i wasn't clear enough:

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

回答1:

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.

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

There are many Android developer support sites, offering a variety of languages.



回答2:

you need to create a service, http://developer.android.com/guide/components/services.html



回答3:

I hope you can tackle it using the function public void onTaskRemoved(Intent rootIntent) {}