I want to add my app to the notification bar so that it always shows, like some apps in the Google Play store.
I want it to be like this screen shot:
In order to have your notification always present, you'll want to set these two flags:
notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
Note that while setting your Service to be in the foreground will also get you an ongoing event, that is a very inappropriate thing to do unless you truly do need your Service to run in the foreground. A music player is a good example of an app that should do that -- the user has an expectation that their music will play without interruption, even when doing many other things with the device.
Most Services, however, can afford to be temporarily stopped by the system when memory is low, and then restarted automatically when memory is available again. So the correct way to think about it is to separate the two ideas.
Service.startForeground()
, but don't think of this as a way to get an ongoing notification.