Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send local notification android when app is closed?

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.

like image 815
Ozymandias Avatar asked Jun 20 '14 12:06

Ozymandias


2 Answers

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.

like image 90
CommonsWare Avatar answered Nov 19 '22 14:11

CommonsWare


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

like image 20
user3505444 Avatar answered Nov 19 '22 15:11

user3505444