android notification in background if app closed?

Jack K Fouani picture Jack K Fouani · Sep 15, 2013 · Viewed 41.5k times · Source

I am trying to display a notification in the Android notifications bar even if my application is closed.

I've tried searching, but I have had no luck finding help.

An example of this is a news application. Even if the phone screen is off or the news application is closed, it can still send a notification for recent news and have it appear in the notification bar.

How might I go about doing this in my own application?

Answer

Idipaolo picture Idipaolo · Sep 15, 2013

You have to build a Service that handles your news and shows notifications when it knows that are new news (Service Doc). The service will run in background even if your application is closed. You need a BroadcastReciever to run the service in background after the boot phase is completed. (Start service after boot).

The service will build your notifications and send them through the NotificationManager.

EDIT: This article may suit your needs