Android – implementing startForeground for a service?


So I’m not sure where/how to implement this method to make my service run in the foreground. Currently I start my service by the following in another activity:

Intent i  new Intent(context, myService.class); 

And then in myServices’ onCreate() I try the startForeground()…?

Notification notification  new Notification();
startForeground(1, notification);

So yeah I’m a bit lost and unsure of how to implement this.


I’d start by completely filling in the Notification. Here is a sample project demonstrating the use of startForeground().

Answered By – CommonsWare

Leave a Comment