Android - implementing startForeground for a service?

JDS picture JDS · Jun 18, 2011 · Viewed 191.9k times · Source

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); 
context.startService(i);

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.

Answer

CommonsWare picture CommonsWare · Jun 18, 2011

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