7

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.

Ozymandias
  • 89
  • 1
  • 1
  • 6
  • What is a "local notification"? What do you mean by "closed"? – CommonsWare Jun 20 '14 at 12:38
  • Local notification -> Not send by a server, and closed -> killed the process of my app – Ozymandias Jun 20 '14 at 12:40
  • An infinite number of things are not sent by a server. Please explain, **completely and precisely**, what a "local notification" means to you. Do you mean the Android `Notification` class? – CommonsWare Jun 20 '14 at 12:42
  • Yes that's what i mean. Sorry i'm new here, it's hard to explain things when you do understand fully and when english is not your native language. By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver. – Ozymandias Jun 20 '14 at 12:44
  • Refer this you will resolve your issue. [Stackoverflow link](http://stackoverflow.com/questions/39674850/send-a-notification-when-the-app-is-closed/39675175#39675175) – Vaibhav Kadam Sep 27 '16 at 07:43
  • 4
    Just to be clear, I think your question was perfectly clear, some people just like to nit pick (including me, which should tell you something if I thought it was fine). – Trevor Hart Nov 02 '17 at 21:17

2 Answers2

9

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.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

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

DataYoda
  • 771
  • 5
  • 18